etsy 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,22 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Etsy
4
+ class ImageTest < Test::Unit::TestCase
5
+
6
+ describe "An instance of the Image class" do
7
+
8
+ when_populating Image, :from => lambda { read_fixture('getShopListings')[0]['all_images'].first } do
9
+
10
+ value_for :small_square, :is => "http://ny-image2.etsy.com/il_25x25.67765346.jpg"
11
+ value_for :medium_square, :is => "http://ny-image2.etsy.com/il_50x50.67765346.jpg"
12
+ value_for :large_square, :is => "http://ny-image2.etsy.com/il_75x75.67765346.jpg"
13
+ value_for :small, :is => "http://ny-image2.etsy.com/il_155x125.67765346.jpg"
14
+ value_for :medium, :is => "http://ny-image2.etsy.com/il_200x200.67765346.jpg"
15
+ value_for :large, :is => "http://ny-image2.etsy.com/il_430xN.67765346.jpg"
16
+
17
+ end
18
+
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,92 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Etsy
4
+ class ListingTest < Test::Unit::TestCase
5
+
6
+ describe "The Listing class" do
7
+
8
+ it "should be able to find all listings by :user_id" do
9
+ user_id = 122345
10
+
11
+ response = mock_request_cycle :for => "/shops/#{user_id}/listings", :data => 'getShopListings'
12
+
13
+ listing_1, listing_2 = response.result
14
+
15
+ Listing.expects(:new).with(listing_1).returns('listing_1')
16
+ Listing.expects(:new).with(listing_2).returns('listing_2')
17
+
18
+ Listing.find_all_by_user_id(user_id).should == ['listing_1', 'listing_2']
19
+ end
20
+
21
+ end
22
+
23
+ describe "An instance of the Listing class" do
24
+
25
+ when_populating Listing, :from => 'getShopListings' do
26
+
27
+ value_for :id, :is => 24165902
28
+ value_for :state, :is => 'active'
29
+ value_for :title, :is => 'hanging with the bad boys matchbox'
30
+ value_for :description, :is => 'standard size matchbox ...'
31
+ value_for :url, :is => 'http://www.etsy.com/view_listing.php?listing_id=24165902'
32
+ value_for :view_count, :is => 18
33
+ value_for :created, :is => 1240673494.49
34
+ value_for :price, :is => 3
35
+ value_for :quantity, :is => 1
36
+ value_for :currency, :is => 'USD'
37
+ value_for :ending, :is => 1251214294.49
38
+ value_for :tags, :is => %w(accessories matchbox)
39
+ value_for :materials, :is => %w(standard_matchbox notebook_paper)
40
+
41
+ end
42
+
43
+ %w(active removed sold_out expired alchemy).each do |state|
44
+ it "should know that the listing is #{state}" do
45
+ listing = Listing.new
46
+ listing.expects(:state).with().returns(state.sub('_', ''))
47
+
48
+ listing.send("#{state}?".to_sym).should be(true)
49
+ end
50
+
51
+ it "should know that the listing is not #{state}" do
52
+ listing = Listing.new
53
+ listing.expects(:state).with().returns(state.reverse)
54
+
55
+ listing.send("#{state}?".to_sym).should be(false)
56
+ end
57
+ end
58
+
59
+ it "should know the create date" do
60
+ listing = Listing.new
61
+ listing.expects(:created).with().returns(1240673494.49)
62
+
63
+ listing.created_at.should == Time.at(1240673494.49)
64
+ end
65
+
66
+ it "should know the ending date" do
67
+ listing = Listing.new
68
+ listing.expects(:ending).with().returns(1240673494.49)
69
+
70
+ listing.ending_at.should == Time.at(1240673494.49)
71
+ end
72
+
73
+ it "should have associated images" do
74
+ data = read_fixture('getShopListings')[0]
75
+ listing = Listing.new(data)
76
+
77
+ Image.expects(:new).with(data['all_images'][0]).returns('image_1')
78
+ Image.expects(:new).with(data['all_images'][1]).returns('image_2')
79
+
80
+ listing.images.should == ['image_1', 'image_2']
81
+ end
82
+
83
+ it "should have a primary image" do
84
+ listing = Listing.new
85
+ listing.expects(:images).with().returns(%w(one two))
86
+
87
+ listing.image.should == 'one'
88
+ end
89
+
90
+ end
91
+ end
92
+ end
@@ -0,0 +1,74 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Etsy
4
+ class RequestTest < Test::Unit::TestCase
5
+
6
+ describe "The Request class" do
7
+
8
+ it "should know the base URL" do
9
+ Request.base_url.should == 'http://beta-api.etsy.com/v1'
10
+ end
11
+
12
+ it "should be able to retrieve a response" do
13
+ http_response = stub()
14
+ response = stub()
15
+
16
+ Response.expects(:new).with(http_response).returns(response)
17
+
18
+ request = mock {|m| m.expects(:get).with().returns(http_response) }
19
+ Request.expects(:new).with('/user', :one => 'two').returns(request)
20
+
21
+ Request.get('/user', :one => 'two').should == response
22
+ end
23
+ end
24
+
25
+ describe "An instance of the Request class" do
26
+
27
+ it "should append the api_key and detail_level to the parameters" do
28
+ Etsy.expects(:api_key).with().returns('key')
29
+
30
+ r = Request.new('/user', :limit => '1')
31
+ r.parameters.should == {:limit => '1', :api_key => 'key', :detail_level => 'high'}
32
+ end
33
+
34
+ it "should be able to generate query parameters" do
35
+ r = Request.new('/user')
36
+ r.expects(:parameters).with().returns(:api_key => 'foo')
37
+ r.query.should == 'api_key=foo'
38
+ end
39
+
40
+ it "should be able to join multiple query parameters" do
41
+ params = {:limit => '1', :other => 'yes'}
42
+
43
+ r = Request.new('/user', params)
44
+ r.stubs(:parameters).with().returns(params)
45
+
46
+ r.query.split('&').sort.should == %w(limit=1 other=yes)
47
+ end
48
+
49
+ it "should be able to determine the endpoint URI" do
50
+ Request.stubs(:base_url).with().returns('http://example.com')
51
+
52
+ r = Request.new('/user')
53
+ r.stubs(:query).with().returns('a=b')
54
+
55
+ r.endpoint_uri.to_s.should == 'http://example.com/user?a=b'
56
+ end
57
+
58
+ it "should be able to make a successful request" do
59
+ uri = URI.parse('http://example.com')
60
+ response = stub()
61
+
62
+ r = Request.new('/user')
63
+ r.expects(:endpoint_uri).with().returns(uri)
64
+
65
+ Net::HTTP.expects(:get).with(uri).returns(response)
66
+
67
+ r.get.should == response
68
+ end
69
+
70
+ end
71
+
72
+
73
+ end
74
+ end
@@ -0,0 +1,49 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Etsy
4
+ class ResponseTest < Test::Unit::TestCase
5
+
6
+ describe "An instance of the Response class" do
7
+
8
+ it "should be able to decode the JSON data to a hash" do
9
+ data = '{ "foo":"bar" }'
10
+
11
+ r = Response.new(data)
12
+ r.to_hash.should == {'foo' => 'bar'}
13
+ end
14
+
15
+ it "should only decode the JSON data once" do
16
+ JSON.expects(:parse).once.returns({})
17
+
18
+ r = Response.new('{ "foo":"bar" }')
19
+ 2.times { r.to_hash }
20
+ end
21
+
22
+ it "should have a record count" do
23
+ r = Response.new('')
24
+ r.expects(:to_hash).with().returns('count' => 1)
25
+
26
+ r.count.should == 1
27
+ end
28
+
29
+ it "should return an array if there are multiple results entries" do
30
+ r = Response.new('')
31
+ r.expects(:count).with().returns(2)
32
+ r.expects(:to_hash).with().returns('results' => %w(one two))
33
+
34
+ r.result.should == %w(one two)
35
+ end
36
+
37
+ it "should return a single value for results if there is only 1 result" do
38
+ r = Response.new('')
39
+ r.expects(:count).with().returns(1)
40
+ r.expects(:to_hash).with().returns('results' => ['foo'])
41
+
42
+ r.result.should == 'foo'
43
+ end
44
+
45
+ end
46
+
47
+
48
+ end
49
+ end
@@ -0,0 +1,63 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Etsy
4
+ class ShopTest < Test::Unit::TestCase
5
+
6
+ describe "The Shop class" do
7
+
8
+ it "should be able to find a shop by :user_id" do
9
+ user_id = 5327518
10
+ response = mock_request_cycle :for => "/shops/#{user_id}", :data => 'getShopDetails'
11
+
12
+ Shop.expects(:new).with(response.result).returns('shop')
13
+
14
+ Shop.find_by_user_id(user_id).should == 'shop'
15
+ end
16
+
17
+ end
18
+
19
+ describe "An instance of the Shop class" do
20
+
21
+ when_populating Shop, :from => 'getShopDetails' do
22
+
23
+ value_for :user_id, :is => 5327518
24
+ value_for :banner_image_url, :is => 'http://ny-image0.etsy.com/iusb_760x100.6158980.jpg'
25
+ value_for :listing_count, :is => 13
26
+ value_for :updated, :is => 1239717723.36
27
+ value_for :created, :is => 1237430331.15
28
+ value_for :name, :is => 'littletjane'
29
+ value_for :title, :is => 'title text'
30
+ value_for :message, :is => 'message text'
31
+ value_for :announcement, :is => 'announcement text'
32
+
33
+ end
34
+
35
+ it "should know the creation date" do
36
+ shop = Shop.new
37
+ shop.stubs(:created).with().returns(1237430331.15)
38
+
39
+ shop.created_at.should == Time.at(1237430331.15)
40
+ end
41
+
42
+ it "should know the update date" do
43
+ shop = Shop.new
44
+ shop.stubs(:updated).with().returns(1239717723.36)
45
+
46
+ shop.updated_at.should == Time.at(1239717723.36)
47
+ end
48
+
49
+ it "should have a collection of listings" do
50
+ user_id = 123
51
+
52
+ shop = Shop.new
53
+ shop.expects(:user_id).with().returns(user_id)
54
+
55
+ Listing.expects(:find_all_by_user_id).with(user_id).returns('listings')
56
+
57
+ shop.listings.should == 'listings'
58
+ end
59
+
60
+ end
61
+
62
+ end
63
+ end
@@ -0,0 +1,75 @@
1
+ require File.dirname(__FILE__) + '/../../test_helper'
2
+
3
+ module Etsy
4
+ class UserTest < Test::Unit::TestCase
5
+
6
+ describe "The User class" do
7
+
8
+ it "should be able to find a user by username" do
9
+ response = mock_request_cycle :for => '/users/littletjane', :data => 'getUserDetails'
10
+
11
+ User.expects(:new).with(response.result).returns('user')
12
+ User.find_by_username('littletjane').should == 'user'
13
+ end
14
+
15
+ end
16
+
17
+ describe "An instance of the User class" do
18
+
19
+ when_populating User, :from => 'getUserDetails' do
20
+
21
+ value_for :username, :is => 'littletjane'
22
+ value_for :id, :is => 5327518
23
+ value_for :url, :is => 'http://www.etsy.com/shop.php?user_id=5327518'
24
+ value_for :joined, :is => 1191381757.93
25
+ value_for :city, :is => 'Washington, DC'
26
+ value_for :gender, :is => 'female'
27
+ value_for :seller, :is => true
28
+ value_for :last_login, :is => 1239797927.39
29
+ value_for :bio, :is => 'hello!'
30
+
31
+ end
32
+
33
+ it "should know if it is a seller" do
34
+ user = User.new
35
+ user.expects(:seller).with().returns(true)
36
+ user.seller?.should be(true)
37
+ end
38
+
39
+ it "should know the join date" do
40
+ user = User.new
41
+ user.stubs(:joined).with().returns(1191381757.93)
42
+
43
+ user.joined_at.should == Time.at(1191381757.93)
44
+ end
45
+
46
+ it "should know the last login date" do
47
+ user = User.new
48
+ user.stubs(:last_login).with().returns(1239797927.39)
49
+
50
+ user.last_login_at.should == Time.at(1239797927.39)
51
+ end
52
+
53
+ it "should have a shop" do
54
+ user = User.new
55
+ shop = stub()
56
+
57
+ user.stubs(:id).with().returns(1)
58
+ user.stubs(:seller?).with().returns(true)
59
+
60
+ Shop.expects(:find_by_user_id).with(1).returns(shop)
61
+
62
+ user.shop.should == shop
63
+ end
64
+
65
+ it "should not have a shop if the user is not a seller" do
66
+ user = User.new
67
+ user.expects(:seller?).with().returns(false)
68
+
69
+ user.shop.should be(nil)
70
+ end
71
+
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,21 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class EtsyTest < Test::Unit::TestCase
4
+
5
+ describe "The Etsy module" do
6
+
7
+ it "should be able to set and retrieve the API key" do
8
+ Etsy.api_key = 'key'
9
+ Etsy.api_key.should == 'key'
10
+ end
11
+
12
+ it "should be able to find a user by username" do
13
+ user = stub()
14
+
15
+ Etsy::User.expects(:find_by_username).with('littletjane').returns(user)
16
+ Etsy.user('littletjane').should == user
17
+ end
18
+
19
+ end
20
+
21
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: etsy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Patrick Reagan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-04 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: json
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: 1.1.0
24
+ version:
25
+ description:
26
+ email: reaganpr@gmail.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - README.rdoc
33
+ files:
34
+ - README.rdoc
35
+ - Rakefile
36
+ - lib/etsy
37
+ - lib/etsy/image.rb
38
+ - lib/etsy/listing.rb
39
+ - lib/etsy/model.rb
40
+ - lib/etsy/request.rb
41
+ - lib/etsy/response.rb
42
+ - lib/etsy/shop.rb
43
+ - lib/etsy/user.rb
44
+ - lib/etsy/version.rb
45
+ - lib/etsy.rb
46
+ - test/fixtures
47
+ - test/fixtures/getShopDetails.json
48
+ - test/fixtures/getShopListings.json
49
+ - test/fixtures/getUserDetails.json
50
+ - test/test_helper.rb
51
+ - test/unit
52
+ - test/unit/etsy
53
+ - test/unit/etsy/image_test.rb
54
+ - test/unit/etsy/listing_test.rb
55
+ - test/unit/etsy/request_test.rb
56
+ - test/unit/etsy/response_test.rb
57
+ - test/unit/etsy/shop_test.rb
58
+ - test/unit/etsy/user_test.rb
59
+ - test/unit/etsy_test.rb
60
+ has_rdoc: true
61
+ homepage: http://sneaq.net
62
+ post_install_message:
63
+ rdoc_options:
64
+ - --main
65
+ - README.rdoc
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: "0"
79
+ version:
80
+ requirements: []
81
+
82
+ rubyforge_project:
83
+ rubygems_version: 1.3.1
84
+ signing_key:
85
+ specification_version: 2
86
+ summary: Provides a friendly ruby-like interface to the Etsy API
87
+ test_files: []
88
+