milo 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.gitignore CHANGED
@@ -1,17 +1,9 @@
1
+ *.swp
1
2
  *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
3
+ *.swo
4
+ .idea/*
5
+ *.orig
6
+ pkg/*
7
+ .rvmrc
8
+
9
+ test.rb
data/Gemfile.lock ADDED
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ milo (0.0.3)
5
+ activesupport (>= 2.3)
6
+ crack (>= 0.1.8)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (3.2.6)
12
+ i18n (~> 0.6)
13
+ multi_json (~> 1.0)
14
+ crack (0.3.1)
15
+ diff-lcs (1.1.3)
16
+ i18n (0.6.0)
17
+ multi_json (1.3.6)
18
+ rake (0.9.2.2)
19
+ rspec (2.11.0)
20
+ rspec-core (~> 2.11.0)
21
+ rspec-expectations (~> 2.11.0)
22
+ rspec-mocks (~> 2.11.0)
23
+ rspec-core (2.11.1)
24
+ rspec-expectations (2.11.1)
25
+ diff-lcs (~> 1.1.3)
26
+ rspec-mocks (2.11.1)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ milo!
33
+ rake
34
+ rspec
data/README.md CHANGED
@@ -1,6 +1,9 @@
1
- # Milo [![Build Status](https://secure.travis-ci.org/victorhazbun87/milo.png)](https://secure.travis-ci.org/victorhazbun87/milo)
1
+ # Milo [![Build Status](https://secure.travis-ci.org/victorhazbun87/milo.png?branch=master)][travis] [![Dependency Status](https://gemnasium.com/victorhazbun87/milo.png?travis)][gemnasium]
2
2
 
3
- ## Description
3
+ [travis]: http://travis-ci.org/victorhazbun87/milo
4
+ [gemnasium]: https://gemnasium.com/milo/milo
5
+
6
+ ## Description
4
7
 
5
8
  Track in real time the price and availability of every product carried by every location of every merchant through eBay Milo API.
6
9
 
@@ -29,4 +32,3 @@ TODO: Write usage instructions here
29
32
  3. Add tests for it. This is important so I don’t break it in a future version unintentionally.
30
33
  4. Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull).
31
34
  5. Send me a pull request. Bonus points for topic branches.
32
- 6. Dont be mad.
data/lib/console.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'lib/zendesk-api'
2
+ puts <<-TXT
3
+ Stuff here to explain what it does
4
+ TXT
5
+
6
+ include Milo
data/lib/load_milo.rb ADDED
@@ -0,0 +1 @@
1
+ require File.dirname(__FILE__) + "/milo"
data/lib/milo.rb CHANGED
@@ -1,5 +1,18 @@
1
- require "milo/version"
1
+ require 'rubygems'
2
+ require 'curb'
3
+ require 'crack'
4
+ gem 'activesupport'
5
+ require 'active_support'
6
+ require 'active_support/version'
7
+ # need to pull in the pieces we want with Rails 3
8
+ require 'active_support/core_ext' if ActiveSupport::VERSION::MAJOR == 3
2
9
 
3
10
  module Milo
4
- # Your code goes here...
11
+ class Error < StandardError; end
12
+ class CouldNotAuthenticateYou < StandardError; end
5
13
  end
14
+
15
+ require 'milo/version'
16
+ require 'milo/product'
17
+ require 'milo/main'
18
+
data/lib/milo/main.rb ADDED
@@ -0,0 +1,79 @@
1
+ module Milo
2
+ class Main
3
+ attr_accessor :main_url, :format
4
+ attr_reader :response_raw, :response
5
+
6
+ def initialize(key, options = {})
7
+ @key = key
8
+ @options = options
9
+ @format = 'json'
10
+ end
11
+
12
+ def main_url
13
+ url_prefix = @options[:ssl] ? "https://" : "http://"
14
+ url_postfix = "api.x.com/milo/v3/"
15
+ url_prefix + url_postfix
16
+ end
17
+
18
+ def self.to_json(function_name, input)
19
+ if input.is_a?(String)
20
+ input
21
+ else
22
+ input.to_json({:root => function_name})
23
+ end
24
+ end
25
+
26
+ def params_list(list)
27
+ params = "?" + list.map do |k, v|
28
+ if v.is_a?(Array)
29
+ v.map do |val|
30
+ "#{k}[]=#{val}"
31
+ end.join("&")
32
+ else
33
+ "#{k}=#{v}"
34
+ end
35
+ end.join("&")
36
+ end
37
+
38
+ def make_request(end_url)
39
+ result_key = end_url.include?("?") ? "&key=#{@key}" : "?key=#{@key}"
40
+ curl = Curl::Easy.new(main_url + end_url + result_key)
41
+
42
+ if curl.body_str == "<error>A friendly explanation of what went wrong</error>"
43
+ return "string" #raise CouldNotAuthenticateYou
44
+ end
45
+ Response.new(curl, format)
46
+ end
47
+
48
+ class Response
49
+
50
+ attr_reader :status, :body, :headers_raw, :headers, :curl, :url, :data
51
+
52
+ def initialize(curl, format)
53
+ @format=format
54
+ @curl = curl
55
+ @url = curl.url
56
+ @status = curl.response_code
57
+ @body = curl.body_str
58
+ @headers_raw = curl.header_str
59
+ parse_headers
60
+ end
61
+
62
+ def parse_headers
63
+ hs={}
64
+ return hs if headers_raw.nil? or headers_raw==""
65
+ headers_raw.split("\r\n")[1..-1].each do |h|
66
+ # Rails.logger.info h
67
+ m=h.match(/([^:]+):\s?(.*)/)
68
+ next if m.nil? or m[2].nil?
69
+ # Rails.logger.info m.inspect
70
+ hs[m[1]]=m[2]
71
+ end
72
+ @headers=hs
73
+ end
74
+
75
+ end
76
+
77
+ include Milo::Product
78
+ end
79
+ end
@@ -0,0 +1,28 @@
1
+ module Milo
2
+ module Product
3
+
4
+ def get_products(options = {})
5
+ base = "products"
6
+ base.tap do |b|
7
+ b + "?show=#{options[:show]}" if options[:show].present?
8
+ end
9
+ make_request("products")
10
+ end
11
+
12
+ def get_product_by_id(id, options = {})
13
+ base = "products?product_ids=#{id}"
14
+ base.tap do |b|
15
+ b.concat("&show=#{options[:show]}") if options[:show].present?
16
+ end
17
+ make_request(base)
18
+ end
19
+
20
+ def get_product_by_upc(upc, options = {})
21
+ base = "products?q=upc:#{upc}"
22
+ base.tap do |b|
23
+ b + "&show=#{options[:show]}" if options[:show].present?
24
+ end
25
+ make_request(base)
26
+ end
27
+ end
28
+ end
data/lib/milo/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Milo
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
data/milo.gemspec CHANGED
@@ -18,4 +18,8 @@ Gem::Specification.new do |s|
18
18
 
19
19
  s.add_development_dependency "rake"
20
20
  s.add_development_dependency "rspec"
21
+
22
+ s.add_runtime_dependency(%q<crack>, [">= 0.1.8"])
23
+ s.add_runtime_dependency(%q<activesupport>, [">= 2.3"])
24
+
21
25
  end
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+ require "milo"
3
+
4
+ describe Milo::Main do
5
+ before(:each) do
6
+ @key = "this_key"
7
+ @milo = Milo::Main.new(@key)
8
+ end
9
+
10
+ describe "basic" do
11
+ it "should have the correct mail_url with no ssl options" do
12
+ @milo.main_url.should == "http://api.x.com/milo/v3/"
13
+ end
14
+
15
+ it "should have the correct mail_url with ssl options" do
16
+ @milo = Milo::Main.new(@key, :ssl => true)
17
+ @milo.main_url.should == "https://api.x.com/milo/v3/"
18
+ end
19
+ end
20
+
21
+ describe 'make_request' do
22
+ context "product" do
23
+ it "should construct url for product" do
24
+ response = @milo.make_request("products?product_ids=1234")
25
+ response.url.should == "http://api.x.com/milo/v3/products?product_ids=1234&key=#{@key}"
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+ require "milo"
3
+
4
+ describe Milo::Main, 'product api' do
5
+
6
+ before :each do
7
+ @key = "my_key"
8
+ curl_object = Curl::Easy.method(:new)
9
+ Curl::Easy.stub!(:new).and_return do |*args|
10
+ curl = curl_object.call(*args)
11
+ curl.stub!(:perform)
12
+ curl.stub!(:header_str) { "\r\ntest: blah"}
13
+ curl.stub!(:response_code).and_return(200)
14
+ curl
15
+ end
16
+ end
17
+
18
+ it "should be able to list all" do
19
+ milo = Milo::Main.new(@key)
20
+ response = milo.get_products
21
+ response.url.should == "http://api.x.com/milo/v3/products?key=#{@key}"
22
+ response.status.should == 200
23
+ end
24
+
25
+ it "should be able to get by id" do
26
+ milo = Milo::Main.new(@key)
27
+ response = milo.get_product_by_id("20482374")
28
+ response.url.should == "http://api.x.com/milo/v3/products?product_ids=20482374&key=#{@key}"
29
+ response.status.should == 200
30
+ end
31
+
32
+ it "should be able to get by upc" do
33
+ milo = Milo::Main.new(@key)
34
+ response = milo.get_product_by_upc("037000185062")
35
+ response.url.should == "http://api.x.com/milo/v3/products?q=upc:037000185062&key=#{@key}"
36
+ response.status.should == 200
37
+ end
38
+
39
+ it "should be able to get by id with show flag in the show parameter" do
40
+ milo = Milo::Main.new(@key)
41
+ response = milo.get_product_by_id("20482374", show: "PnamePminUpcImg45")
42
+ response.url.should == "http://api.x.com/milo/v3/products?product_ids=20482374&show=PnamePminUpcImg45&key=#{@key}"
43
+ response.status.should == 200
44
+ end
45
+
46
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: milo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-19 00:00:00.000000000 Z
12
+ date: 2012-07-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -43,6 +43,38 @@ dependencies:
43
43
  - - ! '>='
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: crack
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 0.1.8
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 0.1.8
62
+ - !ruby/object:Gem::Dependency
63
+ name: activesupport
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '2.3'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '2.3'
46
78
  description: Track in real time the price and availability of every product carried
47
79
  by every location of every merchant through eBay Milo API.
48
80
  email:
@@ -56,14 +88,20 @@ files:
56
88
  - .travis.yml
57
89
  - CHANGELOG.md
58
90
  - Gemfile
91
+ - Gemfile.lock
59
92
  - LICENSE
60
93
  - README
61
94
  - README.md
62
95
  - Rakefile
96
+ - lib/console.rb
97
+ - lib/load_milo.rb
63
98
  - lib/milo.rb
99
+ - lib/milo/main.rb
100
+ - lib/milo/product.rb
64
101
  - lib/milo/version.rb
65
102
  - milo.gemspec
66
- - spec/milo/milo_spec.rb
103
+ - spec/milo/main_spec.rb
104
+ - spec/milo/product_spec.rb
67
105
  - spec/spec_helper.rb
68
106
  homepage: https://github.com/victorhazbun87/milo
69
107
  licenses: []
@@ -79,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
117
  version: '0'
80
118
  segments:
81
119
  - 0
82
- hash: 2400936919744768789
120
+ hash: 4216257872377755696
83
121
  required_rubygems_version: !ruby/object:Gem::Requirement
84
122
  none: false
85
123
  requirements:
@@ -88,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
126
  version: '0'
89
127
  segments:
90
128
  - 0
91
- hash: 2400936919744768789
129
+ hash: 4216257872377755696
92
130
  requirements: []
93
131
  rubyforge_project:
94
132
  rubygems_version: 1.8.24
@@ -96,5 +134,6 @@ signing_key:
96
134
  specification_version: 3
97
135
  summary: Ruby wrapper for the eBay Milo API
98
136
  test_files:
99
- - spec/milo/milo_spec.rb
137
+ - spec/milo/main_spec.rb
138
+ - spec/milo/product_spec.rb
100
139
  - spec/spec_helper.rb
@@ -1,5 +0,0 @@
1
- # encoding: utf-8
2
-
3
- describe Milo do
4
- pending
5
- end