milo 0.0.6 → 0.0.7
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/CHANGELOG.md +5 -0
- data/Gemfile.lock +22 -14
- data/README.md +3 -23
- data/lib/milo/main.rb +3 -2
- data/lib/milo/product.rb +21 -16
- data/lib/milo/version.rb +1 -1
- data/milo.gemspec +4 -1
- data/spec/milo/main_spec.rb +12 -6
- data/spec/milo/product_spec.rb +22 -27
- data/spec/spec_helper.rb +18 -0
- metadata +51 -9
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
milo (0.0.
|
4
|
+
milo (0.0.7.alpha)
|
5
5
|
activesupport
|
6
6
|
crack
|
7
7
|
curb
|
@@ -9,28 +9,36 @@ PATH
|
|
9
9
|
GEM
|
10
10
|
remote: https://rubygems.org/
|
11
11
|
specs:
|
12
|
-
activesupport (3.2.
|
12
|
+
activesupport (3.2.11)
|
13
13
|
i18n (~> 0.6)
|
14
14
|
multi_json (~> 1.0)
|
15
|
-
crack (0.3.
|
16
|
-
curb (0.8.
|
15
|
+
crack (0.3.2)
|
16
|
+
curb (0.8.3)
|
17
17
|
diff-lcs (1.1.3)
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
rspec
|
23
|
-
|
24
|
-
|
25
|
-
rspec
|
26
|
-
|
18
|
+
fakeweb (1.3.0)
|
19
|
+
i18n (0.6.1)
|
20
|
+
json_spec (1.1.0)
|
21
|
+
multi_json (~> 1.0)
|
22
|
+
rspec (~> 2.0)
|
23
|
+
multi_json (1.5.0)
|
24
|
+
rake (10.0.3)
|
25
|
+
rspec (2.12.0)
|
26
|
+
rspec-core (~> 2.12.0)
|
27
|
+
rspec-expectations (~> 2.12.0)
|
28
|
+
rspec-mocks (~> 2.12.0)
|
29
|
+
rspec-core (2.12.2)
|
30
|
+
rspec-expectations (2.12.1)
|
27
31
|
diff-lcs (~> 1.1.3)
|
28
|
-
rspec-mocks (2.
|
32
|
+
rspec-mocks (2.12.2)
|
33
|
+
vcr (2.4.0)
|
29
34
|
|
30
35
|
PLATFORMS
|
31
36
|
ruby
|
32
37
|
|
33
38
|
DEPENDENCIES
|
39
|
+
fakeweb
|
40
|
+
json_spec
|
34
41
|
milo!
|
35
42
|
rake
|
36
43
|
rspec
|
44
|
+
vcr
|
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Milo [][travis] [][gemnasium]
|
2
2
|
|
3
3
|
[travis]: http://travis-ci.org/victorhazbun87/milo
|
4
|
-
[gemnasium]: https://gemnasium.com/
|
4
|
+
[gemnasium]: https://gemnasium.com/victorhazbun87/milo
|
5
5
|
|
6
6
|
## Description
|
7
7
|
|
@@ -22,29 +22,9 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
$ gem install milo
|
24
24
|
|
25
|
-
##
|
25
|
+
## Getting Started
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
milo = Milo::Main.new("ec17621f92c4b199a7a041bfe27a0c00")
|
30
|
-
|
31
|
-
Get all products:
|
32
|
-
|
33
|
-
milo.get_products
|
34
|
-
|
35
|
-
Get product by id:
|
36
|
-
|
37
|
-
milo.get_product_by_id("20482374")
|
38
|
-
|
39
|
-
Get product by upc code:
|
40
|
-
|
41
|
-
milo.get_product_by_upc("037000185062")
|
42
|
-
|
43
|
-
More complex, find by id and pass show options for products:
|
44
|
-
|
45
|
-
milo.get_product_by_id("20482374", show: "PnamePminUpcImg45")
|
46
|
-
|
47
|
-
Note: Read about show flag here -> https://www.x.com/developers/documentation-tools/milo/endpoints.html#products-endpoint
|
27
|
+
See the [milo home page](http://victorhazbun87.github.com/milo) for the simple steps process.
|
48
28
|
|
49
29
|
|
50
30
|
## Contributing to Milo
|
data/lib/milo/main.rb
CHANGED
@@ -13,9 +13,10 @@ module Milo
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def make_request(end_url)
|
16
|
-
result_key =
|
16
|
+
result_key = "&key=#{@key}"
|
17
17
|
curl = Curl::Easy.perform(main_url + end_url + result_key)
|
18
|
-
Response.new(curl)
|
18
|
+
response = Response.new(curl)
|
19
|
+
JSON.parse(response.body)
|
19
20
|
end
|
20
21
|
|
21
22
|
class Response
|
data/lib/milo/product.rb
CHANGED
@@ -1,28 +1,33 @@
|
|
1
1
|
module Milo
|
2
2
|
module Product
|
3
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
4
|
def get_product_by_id(id, options = {})
|
13
5
|
base = "products?product_ids=#{id}"
|
14
|
-
base
|
15
|
-
|
16
|
-
end
|
17
|
-
make_request(base)
|
6
|
+
result = apply_flag(base, options)
|
7
|
+
make_request(result)
|
18
8
|
end
|
19
9
|
|
20
10
|
def get_product_by_upc(upc, options = {})
|
21
11
|
base = "products?q=upc:#{upc}"
|
22
|
-
base
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
result = apply_flag(base, options)
|
13
|
+
make_request(result)
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_product_by_postal_code(code, options = {})
|
17
|
+
base = "products?postal_code=#{code}"
|
18
|
+
result = apply_flag(base, options)
|
19
|
+
make_request(result)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def apply_flag(base, options = {})
|
25
|
+
return base if options == {}
|
26
|
+
hash = {}
|
27
|
+
hash.merge!(show: options[:show]) if options[:show]
|
28
|
+
hash.merge!(q: options[:q]) if options[:q]
|
29
|
+
hash.merge!(show_defaults: options[:show_defaults]) if options[:show_defaults]
|
30
|
+
base + "&" + hash.to_query
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
data/lib/milo/version.rb
CHANGED
data/milo.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |s|
|
|
9
9
|
s.email = ["victorhazbun87@gmail.com"]
|
10
10
|
s.description = %q{Track in real time the price and availability of every product carried by every location of every merchant through eBay Milo API.}
|
11
11
|
s.summary = %q{Ruby wrapper for the eBay Milo API}
|
12
|
-
s.homepage = "
|
12
|
+
s.homepage = "http://victorhazbun87.github.com/milo/"
|
13
13
|
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
@@ -18,6 +18,9 @@ Gem::Specification.new do |s|
|
|
18
18
|
|
19
19
|
s.add_development_dependency "rake"
|
20
20
|
s.add_development_dependency "rspec"
|
21
|
+
s.add_development_dependency "vcr"
|
22
|
+
s.add_development_dependency "fakeweb"
|
23
|
+
s.add_development_dependency "json_spec"
|
21
24
|
s.add_dependency "curb"
|
22
25
|
s.add_dependency "activesupport"
|
23
26
|
s.add_dependency "crack"
|
data/spec/milo/main_spec.rb
CHANGED
@@ -1,23 +1,29 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "milo"
|
3
|
+
require 'spec_helper'
|
3
4
|
|
4
5
|
describe Milo::Main do
|
5
6
|
before(:each) do
|
6
|
-
|
7
|
-
|
7
|
+
@key = "ffbefff2a246f4c53c0d04ed50bb4707"
|
8
|
+
@milo = Milo::Main.new(@key)
|
8
9
|
end
|
9
10
|
|
10
11
|
describe "basic" do
|
11
|
-
it "should have the correct mail_url" do
|
12
|
+
it "should have the correct mail_url", :vcr do
|
12
13
|
@milo.main_url.should == "https://api.x.com/milo/v3/"
|
13
14
|
end
|
14
15
|
end
|
15
16
|
|
16
17
|
describe 'make_request' do
|
17
18
|
context "product" do
|
18
|
-
it "should
|
19
|
-
|
20
|
-
|
19
|
+
it "should contains one product matching with given a id", :vcr do
|
20
|
+
result = @milo.make_request("products?product_ids=20482374")
|
21
|
+
result.to_json.should have_json_size(1).at_path("products")
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should contains the product with the same id given in the path", :vcr do
|
25
|
+
result = @milo.make_request("products?product_ids=20482374")
|
26
|
+
result.to_json.should have_json_type(Integer).at_path("products/0/product_id")
|
21
27
|
end
|
22
28
|
end
|
23
29
|
end
|
data/spec/milo/product_spec.rb
CHANGED
@@ -1,48 +1,43 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "milo"
|
3
|
+
require 'spec_helper'
|
3
4
|
|
4
5
|
describe Milo::Main, 'product api' do
|
5
6
|
|
6
7
|
before :each do
|
7
|
-
@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.stub!(:body_str).and_return("{\"pagination\": {\"total_results\": 1, \"per_page\": 30, \"total_pages\": 1, \"page\": 0}, \"products\": [{\"merchants\": [4483], \"min_price\": null, \"name\": \"REDI2SET 43\\\" x 14\\\" Wavy Glass Pattern Frameless Replacement Glass Block Window\", \"max_price\": null, \"product_id\": 20482374}]}")
|
15
|
-
curl
|
16
|
-
end
|
8
|
+
@key = "ffbefff2a246f4c53c0d04ed50bb4707"
|
17
9
|
end
|
18
10
|
|
19
|
-
it "should be able to
|
11
|
+
it "should be able to get by id", :vcr do
|
20
12
|
milo = Milo::Main.new(@key)
|
21
|
-
response = milo.
|
22
|
-
response.
|
23
|
-
response.status.should == 200
|
13
|
+
response = milo.get_product_by_id("20482374")
|
14
|
+
response.to_json.should have_json_size(1).at_path("products")
|
24
15
|
end
|
25
16
|
|
26
|
-
it "should be able to get by
|
17
|
+
it "should be able to get by upc", :vcr do
|
27
18
|
milo = Milo::Main.new(@key)
|
28
|
-
response = milo.
|
29
|
-
response.
|
30
|
-
response.body.should =~ /Wavy Glass Pattern Frameless Replacement Glass Block Window/
|
31
|
-
response.status.should == 200
|
19
|
+
response = milo.get_product_by_upc("037000185062")
|
20
|
+
response.to_json.should have_json_size(1).at_path("products")
|
32
21
|
end
|
33
22
|
|
34
|
-
it "should be able to get by
|
23
|
+
it "should be able to get by id with show flag in the show parameter", :vcr do
|
35
24
|
milo = Milo::Main.new(@key)
|
36
|
-
response = milo.
|
37
|
-
response.
|
38
|
-
response.
|
25
|
+
response = milo.get_product_by_id("20482374", {show: "PnamePminUpcImg45"})
|
26
|
+
response.to_json.should have_json_size(1).at_path("products")
|
27
|
+
response.to_json.should include_json('http://imagethumbnails.milo.com/035/340/575/45/35340237_34484575_45.jpg'.to_json).at_path("products/0/image_45")
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should be able to get by postal code", :vcr do
|
31
|
+
milo = Milo::Main.new(@key)
|
32
|
+
response = milo.get_product_by_postal_code("07032")
|
33
|
+
response.to_json.should have_json_size(30).at_path("products")
|
39
34
|
end
|
40
35
|
|
41
|
-
|
36
|
+
it "should be able to get by postal code with many flags", :vcr do
|
42
37
|
milo = Milo::Main.new(@key)
|
43
|
-
response = milo.
|
44
|
-
response.
|
45
|
-
response.
|
38
|
+
p response = milo.get_product_by_postal_code("07032", {q: "basketball", show_defaults: "false", show: "PidPnameMidsPminPmaxDescPurlImg200Rate"})
|
39
|
+
response.to_json.should have_json_size(30).at_path("products")
|
40
|
+
response.to_json.should include_json("Lifetime 44 in. Streamline Basketball System".to_json).at_path("products/0/name")
|
46
41
|
end
|
47
42
|
|
48
43
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,20 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'milo'
|
3
|
+
require 'base64'
|
4
|
+
require 'fakeweb'
|
5
|
+
require 'vcr'
|
6
|
+
require 'json_spec'
|
7
|
+
|
8
|
+
VCR.configure do |c|
|
9
|
+
c.cassette_library_dir = 'fixtures/vcr_cassettes'
|
10
|
+
c.hook_into :fakeweb
|
11
|
+
end
|
12
|
+
|
13
|
+
RSpec.configure do |c|
|
14
|
+
c.treat_symbols_as_metadata_keys_with_true_values = true
|
15
|
+
c.around(:each, :vcr) do |example|
|
16
|
+
name = example.metadata[:full_description].split(/\s+/, 2).join("/").underscore.gsub(/[^\w\/]+/, "_")
|
17
|
+
options = example.metadata.slice(:record, :match_requests_on).except(:example_group)
|
18
|
+
VCR.use_cassette(name, options) { example.call }
|
19
|
+
end
|
20
|
+
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.
|
4
|
+
version: 0.0.7
|
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:
|
12
|
+
date: 2013-02-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -43,6 +43,54 @@ dependencies:
|
|
43
43
|
- - ! '>='
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: vcr
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: fakeweb
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: json_spec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
46
94
|
- !ruby/object:Gem::Dependency
|
47
95
|
name: curb
|
48
96
|
requirement: !ruby/object:Gem::Requirement
|
@@ -119,7 +167,7 @@ files:
|
|
119
167
|
- spec/milo/main_spec.rb
|
120
168
|
- spec/milo/product_spec.rb
|
121
169
|
- spec/spec_helper.rb
|
122
|
-
homepage:
|
170
|
+
homepage: http://victorhazbun87.github.com/milo/
|
123
171
|
licenses: []
|
124
172
|
post_install_message:
|
125
173
|
rdoc_options: []
|
@@ -131,18 +179,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
179
|
- - ! '>='
|
132
180
|
- !ruby/object:Gem::Version
|
133
181
|
version: '0'
|
134
|
-
segments:
|
135
|
-
- 0
|
136
|
-
hash: -878125091368183299
|
137
182
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
138
183
|
none: false
|
139
184
|
requirements:
|
140
185
|
- - ! '>='
|
141
186
|
- !ruby/object:Gem::Version
|
142
187
|
version: '0'
|
143
|
-
segments:
|
144
|
-
- 0
|
145
|
-
hash: -878125091368183299
|
146
188
|
requirements: []
|
147
189
|
rubyforge_project:
|
148
190
|
rubygems_version: 1.8.24
|