Permalink
Browse files

releasing v0.0.7

  • Loading branch information...
1 parent 7bdcb39 commit cd29704cdaad8f26044d47f97e681a034b301476 @victorhazbunanuff victorhazbunanuff committed Feb 3, 2013
Showing with 102 additions and 63 deletions.
  1. +5 −0 CHANGELOG.md
  2. +21 −13 Gemfile.lock
  3. +3 −2 lib/milo/main.rb
  4. +17 −14 lib/milo/product.rb
  5. +1 −1 lib/milo/version.rb
  6. +3 −0 milo.gemspec
  7. +12 −6 spec/milo/main_spec.rb
  8. +22 −27 spec/milo/product_spec.rb
  9. +18 −0 spec/spec_helper.rb
View
@@ -1,3 +1,8 @@
+## v.0.0.7
+* get_products deprecated
+* responses are parsed in JSON
+* find products by postal code
+
## v.0.06
* get products
View
@@ -9,28 +9,36 @@ PATH
GEM
remote: https://rubygems.org/
specs:
- activesupport (3.2.6)
+ activesupport (3.2.11)
i18n (~> 0.6)
multi_json (~> 1.0)
- crack (0.3.1)
- curb (0.8.1)
+ crack (0.3.2)
+ curb (0.8.3)
diff-lcs (1.1.3)
- i18n (0.6.0)
- multi_json (1.3.6)
- rake (0.9.2.2)
- rspec (2.11.0)
- rspec-core (~> 2.11.0)
- rspec-expectations (~> 2.11.0)
- rspec-mocks (~> 2.11.0)
- rspec-core (2.11.1)
- rspec-expectations (2.11.1)
+ fakeweb (1.3.0)
+ i18n (0.6.1)
+ json_spec (1.1.0)
+ multi_json (~> 1.0)
+ rspec (~> 2.0)
+ multi_json (1.5.0)
+ rake (10.0.3)
+ rspec (2.12.0)
+ rspec-core (~> 2.12.0)
+ rspec-expectations (~> 2.12.0)
+ rspec-mocks (~> 2.12.0)
+ rspec-core (2.12.2)
+ rspec-expectations (2.12.1)
diff-lcs (~> 1.1.3)
- rspec-mocks (2.11.1)
+ rspec-mocks (2.12.2)
+ vcr (2.4.0)
PLATFORMS
ruby
DEPENDENCIES
+ fakeweb
+ json_spec
milo!
rake
rspec
+ vcr
View
@@ -13,9 +13,10 @@ def main_url
end
def make_request(end_url)
- result_key = end_url.include?("?") ? "&key=#{@key}" : "?key=#{@key}"
+ result_key = "&key=#{@key}"
curl = Curl::Easy.perform(main_url + end_url + result_key)
- Response.new(curl)
+ response = Response.new(curl)
+ JSON.parse(response.body)
end
class Response
View
@@ -1,30 +1,33 @@
module Milo
module Product
- def get_products(options = {})
- base = "products"
- apply_flag(base, "?", options[:show])
- make_request(base)
- end
-
def get_product_by_id(id, options = {})
base = "products?product_ids=#{id}"
- apply_flag(base, "&", options[:show])
- make_request(base)
+ result = apply_flag(base, options)
+ make_request(result)
end
def get_product_by_upc(upc, options = {})
base = "products?q=upc:#{upc}"
- apply_flag(base, "&", options[:show])
- make_request(base)
+ result = apply_flag(base, options)
+ make_request(result)
+ end
+
+ def get_product_by_postal_code(code, options = {})
+ base = "products?postal_code=#{code}"
+ result = apply_flag(base, options)
+ make_request(result)
end
private
- def apply_flag(base, identifier, flag)
- base.tap do |b|
- b.concat identifier.concat "show=#{flag}" if flag.present?
- end
+ def apply_flag(base, options = {})
+ return base if options == {}
+ hash = {}
+ hash.merge!(show: options[:show]) if options[:show]
+ hash.merge!(q: options[:q]) if options[:q]
+ hash.merge!(show_defaults: options[:show_defaults]) if options[:show_defaults]
+ base + "&" + hash.to_query
end
end
end
View
@@ -1,3 +1,3 @@
module Milo
- VERSION = "0.0.7.alpha"
+ VERSION = "0.0.7"
end
View
@@ -18,6 +18,9 @@ Gem::Specification.new do |s|
s.add_development_dependency "rake"
s.add_development_dependency "rspec"
+ s.add_development_dependency "vcr"
+ s.add_development_dependency "fakeweb"
+ s.add_development_dependency "json_spec"
s.add_dependency "curb"
s.add_dependency "activesupport"
s.add_dependency "crack"
View
@@ -1,23 +1,29 @@
# encoding: utf-8
require "milo"
+require 'spec_helper'
describe Milo::Main do
before(:each) do
- @key = "this_key"
- @milo = Milo::Main.new(@key)
+ @key = "ffbefff2a246f4c53c0d04ed50bb4707"
+ @milo = Milo::Main.new(@key)
end
describe "basic" do
- it "should have the correct mail_url" do
+ it "should have the correct mail_url", :vcr do
@milo.main_url.should == "https://api.x.com/milo/v3/"
end
end
describe 'make_request' do
context "product" do
- it "should construct url for product" do
- response = @milo.make_request("products?product_ids=1234")
- response.url.should == "https://api.x.com/milo/v3/products?product_ids=1234&key=#{@key}"
+ it "should contains one product matching with given a id", :vcr do
+ result = @milo.make_request("products?product_ids=20482374")
+ result.to_json.should have_json_size(1).at_path("products")
+ end
+
+ it "should contains the product with the same id given in the path", :vcr do
+ result = @milo.make_request("products?product_ids=20482374")
+ result.to_json.should have_json_type(Integer).at_path("products/0/product_id")
end
end
end
View
@@ -1,48 +1,43 @@
# encoding: utf-8
require "milo"
+require 'spec_helper'
describe Milo::Main, 'product api' do
before :each do
- @key = "my_key"
- curl_object = Curl::Easy.method(:new)
- Curl::Easy.stub!(:new).and_return do |*args|
- curl = curl_object.call(*args)
- curl.stub!(:perform)
- curl.stub!(:header_str) { "\r\ntest: blah"}
- curl.stub!(:response_code).and_return(200)
- 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}]}")
- curl
- end
+ @key = "ffbefff2a246f4c53c0d04ed50bb4707"
end
- it "should be able to list all" do
+ it "should be able to get by id", :vcr do
milo = Milo::Main.new(@key)
- response = milo.get_products
- response.url.should == "https://api.x.com/milo/v3/products?key=#{@key}"
- response.status.should == 200
+ response = milo.get_product_by_id("20482374")
+ response.to_json.should have_json_size(1).at_path("products")
end
- it "should be able to get by id" do
+ it "should be able to get by upc", :vcr do
milo = Milo::Main.new(@key)
- response = milo.get_product_by_id("20482374")
- response.url.should == "https://api.x.com/milo/v3/products?product_ids=20482374&key=#{@key}"
- response.body.should =~ /Wavy Glass Pattern Frameless Replacement Glass Block Window/
- response.status.should == 200
+ response = milo.get_product_by_upc("037000185062")
+ response.to_json.should have_json_size(1).at_path("products")
end
- it "should be able to get by upc" do
+ it "should be able to get by id with show flag in the show parameter", :vcr do
milo = Milo::Main.new(@key)
- response = milo.get_product_by_upc("037000185062")
- response.url.should == "https://api.x.com/milo/v3/products?q=upc:037000185062&key=#{@key}"
- response.status.should == 200
+ response = milo.get_product_by_id("20482374", {show: "PnamePminUpcImg45"})
+ response.to_json.should have_json_size(1).at_path("products")
+ 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")
+ end
+
+ it "should be able to get by postal code", :vcr do
+ milo = Milo::Main.new(@key)
+ response = milo.get_product_by_postal_code("07032")
+ response.to_json.should have_json_size(30).at_path("products")
end
- it "should be able to get by id with show flag in the show parameter" do
+ it "should be able to get by postal code with many flags", :vcr do
milo = Milo::Main.new(@key)
- response = milo.get_product_by_id("20482374", show: "PnamePminUpcImg45")
- response.url.should == "https://api.x.com/milo/v3/products?product_ids=20482374&show=PnamePminUpcImg45&key=#{@key}"
- response.status.should == 200
+ p response = milo.get_product_by_postal_code("07032", {q: "basketball", show_defaults: "false", show: "PidPnameMidsPminPmaxDescPurlImg200Rate"})
+ response.to_json.should have_json_size(30).at_path("products")
+ response.to_json.should include_json("Lifetime 44 in. Streamline Basketball System".to_json).at_path("products/0/name")
end
end
View
@@ -1,2 +1,20 @@
require 'rubygems'
require 'milo'
+require 'base64'
+require 'fakeweb'
+require 'vcr'
+require 'json_spec'
+
+VCR.configure do |c|
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
+ c.hook_into :fakeweb
+end
+
+RSpec.configure do |c|
+ c.treat_symbols_as_metadata_keys_with_true_values = true
+ c.around(:each, :vcr) do |example|
+ name = example.metadata[:full_description].split(/\s+/, 2).join("/").underscore.gsub(/[^\w\/]+/, "_")
+ options = example.metadata.slice(:record, :match_requests_on).except(:example_group)
+ VCR.use_cassette(name, options) { example.call }
+ end
+end

0 comments on commit cd29704

Please sign in to comment.