etsy 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/README.rdoc +102 -19
  2. data/Rakefile +5 -5
  3. data/lib/etsy.rb +104 -26
  4. data/lib/etsy/basic_client.rb +26 -0
  5. data/lib/etsy/image.rb +19 -16
  6. data/lib/etsy/listing.rb +30 -27
  7. data/lib/etsy/model.rb +12 -49
  8. data/lib/etsy/request.rb +41 -18
  9. data/lib/etsy/response.rb +17 -11
  10. data/lib/etsy/secure_client.rb +79 -0
  11. data/lib/etsy/shop.rb +42 -18
  12. data/lib/etsy/user.rb +39 -34
  13. data/lib/etsy/verification_request.rb +17 -0
  14. data/lib/etsy/version.rb +4 -4
  15. data/test/fixtures/image/findAllListingImages.json +102 -0
  16. data/test/fixtures/listing/findAllShopListingsActive.json +69 -0
  17. data/test/fixtures/shop/findAllShop.json +1 -0
  18. data/test/fixtures/shop/findAllShop.single.json +1 -0
  19. data/test/fixtures/shop/getShop.multiple.json +1 -0
  20. data/test/fixtures/shop/getShop.single.json +32 -0
  21. data/test/fixtures/user/getUser.multiple.json +29 -0
  22. data/test/fixtures/user/getUser.single.json +13 -0
  23. data/test/fixtures/user/getUser.single.private.json +18 -0
  24. data/test/test_helper.rb +27 -42
  25. data/test/unit/etsy/basic_client_test.rb +28 -0
  26. data/test/unit/etsy/image_test.rb +36 -15
  27. data/test/unit/etsy/listing_test.rb +84 -66
  28. data/test/unit/etsy/request_test.rb +121 -39
  29. data/test/unit/etsy/response_test.rb +20 -20
  30. data/test/unit/etsy/secure_client_test.rb +110 -0
  31. data/test/unit/etsy/shop_test.rb +74 -40
  32. data/test/unit/etsy/user_test.rb +65 -61
  33. data/test/unit/etsy/verification_request_test.rb +26 -0
  34. data/test/unit/etsy_test.rb +91 -10
  35. metadata +61 -17
  36. data/test/fixtures/getShopDetails.json +0 -70
  37. data/test/fixtures/getShopListings.json +0 -135
  38. data/test/fixtures/getUserDetails.json +0 -34
@@ -1,59 +1,93 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
2
 
3
3
  module Etsy
4
4
  class ShopTest < Test::Unit::TestCase
5
5
 
6
- describe "The Shop class" do
6
+ context "The Shop class" do
7
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'
8
+ should "be able to find a single shop" do
9
+ shops = mock_request('/shops/littletjane', {}, 'Shop', 'getShop.single.json')
10
+ Shop.find('littletjane').should == shops.first
11
+ end
12
+
13
+ should "be able to find multiple shops" do
14
+ shops = mock_request('/shops/littletjane,reagent', {}, 'Shop', 'getShop.multiple.json')
15
+ Shop.find('littletjane', 'reagent').should == shops
16
+ end
11
17
 
12
- Shop.expects(:new).with(response.result).returns('shop')
18
+ should "be able to find all shops" do
19
+ shops = mock_request('/shops', {}, 'Shop', 'findAllShop.json')
20
+ Shop.all.should == shops
21
+ end
22
+
23
+ should "return an array of shops if there is only 1 result returned" do
24
+ shops = mock_request('/shops', {}, 'Shop', 'findAllShop.single.json')
25
+ Shop.all.should == shops
26
+ end
13
27
 
14
- Shop.find_by_user_id(user_id).should == 'shop'
28
+ should "allow a configurable limit when finding all shops" do
29
+ shops = mock_request('/shops', {:limit => 100}, 'Shop', 'findAllShop.json')
30
+ Shop.all(:limit => 100).should == shops
15
31
  end
16
32
 
17
33
  end
18
34
 
19
- describe "An instance of the Shop class" do
35
+ context "An instance of the Shop class" do
20
36
 
21
- when_populating Shop, :from => 'getShopDetails' do
37
+ context "with response data" do
38
+ setup do
39
+ data = read_fixture('shop/getShop.single.json')
40
+ @shop = Shop.new(data.first)
41
+ end
22
42
 
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'
43
+ should "have a value for :id" do
44
+ @shop.id.should == 5500349
45
+ end
46
+
47
+ should "have a value for :user_id" do
48
+ @shop.user_id.should == 5327518
49
+ end
50
+
51
+ should "have a value for :image_url" do
52
+ @shop.image_url.should == "http://ny-image2.etsy.com/iusb_760x100.7358402.jpg"
53
+ end
54
+
55
+ should "have a value for :active_listings_count" do
56
+ @shop.active_listings_count.should == 0
57
+ end
58
+
59
+ should "have a value for :updated_at" do
60
+ @shop.updated_at.should == Time.at(1274923984)
61
+ end
62
+
63
+ should "have a value for :created_at" do
64
+ @shop.created_at.should == Time.at(1237430331)
65
+ end
66
+
67
+ should "have a value for :name" do
68
+ @shop.name.should == "littletjane"
69
+ end
70
+
71
+ should "have a value for :title" do
72
+ @shop.title.should == "a cute and crafty mix of handmade goods."
73
+ end
74
+
75
+ should "have a value for :message" do
76
+ @shop.message.should == "thanks!"
77
+ end
78
+
79
+ should "have a value for :announcement" do
80
+ @shop.announcement.should == "announcement"
81
+ end
32
82
 
33
83
  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
-
84
+
85
+ should "have a collection of listings" do
52
86
  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
-
87
+ shop.stubs(:id).with().returns(1)
88
+
89
+ Listing.stubs(:find_all_by_shop_id).with(1).returns('listings')
90
+
57
91
  shop.listings.should == 'listings'
58
92
  end
59
93
 
@@ -1,75 +1,79 @@
1
- require File.dirname(__FILE__) + '/../../test_helper'
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
2
 
3
3
  module Etsy
4
4
  class UserTest < Test::Unit::TestCase
5
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
-
6
+ context "The User class" do
7
+
8
+ should "be able to find a single user" do
9
+ users = mock_request('/users/littletjane', {}, 'User', 'getUser.single.json')
10
+ User.find('littletjane').should == users.first
31
11
  end
32
12
 
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)
13
+ should "be able to find multiple users" do
14
+ users = mock_request('/users/littletjane,reagent', {}, 'User', 'getUser.multiple.json')
15
+ User.find('littletjane', 'reagent').should == users
37
16
  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)
17
+
18
+ should "be able to find the current logged in user" do
19
+ oauth_keys = {:access_token => 'token', :access_secret => 'secret'}
20
+ users = mock_request('/users/__SELF__', oauth_keys, 'User', 'getUser.single.json')
21
+ User.myself('token', 'secret').should == users.first
44
22
  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)
23
+ end
24
+
25
+ context "An instance of the User class" do
26
+
27
+ context "with public response data" do
28
+ setup do
29
+ data = read_fixture('user/getUser.single.json')
30
+ @user = User.new(data.first)
31
+ end
32
+
33
+ should "have an ID" do
34
+ @user.id.should == 5327518
35
+ end
36
+
37
+ should "have a :username" do
38
+ @user.username.should == 'littletjane'
39
+ end
40
+
41
+ should "have a value for :created" do
42
+ @user.created.should == 1191381578
43
+ end
44
+
45
+ should "not have an email address" do
46
+ @user.email.should be_nil
47
+ end
51
48
  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
49
+
50
+ context "with private response data" do
51
+ setup do
52
+ data = read_fixture('user/getUser.single.private.json')
53
+ @user = User.new(data.first)
54
+ end
55
+
56
+ should "have an email address" do
57
+ @user.email.should == 'reaganpr@gmail.com'
58
+ end
63
59
  end
64
-
65
- it "should not have a shop if the user is not a seller" do
60
+
61
+ should "know when the user was created" do
66
62
  user = User.new
67
- user.expects(:seller?).with().returns(false)
68
-
69
- user.shop.should be(nil)
63
+ user.stubs(:created).returns(1)
64
+
65
+ user.created_at.should == Time.at(1)
70
66
  end
71
-
72
67
  end
73
-
68
+
69
+ should "know the shop for a user" do
70
+ user = User.new
71
+ user.stubs(:username).with().returns('username')
72
+
73
+ Shop.stubs(:find).with('username').returns('shop')
74
+
75
+ user.shop.should == 'shop'
76
+ end
77
+
74
78
  end
75
- end
79
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ module Etsy
4
+ class VerificationRequestTest < Test::Unit::TestCase
5
+
6
+ context "An instance of the VerificationRequest class" do
7
+ setup { @request = VerificationRequest.new }
8
+
9
+ should "have a client" do
10
+ SecureClient.stubs(:new).returns('client')
11
+ @request.client.should == 'client'
12
+ end
13
+
14
+ should "know the url" do
15
+ client = stub()
16
+ client.stubs(:request_token).returns(stub(:authorize_url => 'http://www.etsy.com?foo=bar', :secret => 'secret'))
17
+
18
+ @request.stubs(:client).returns(client)
19
+
20
+ @request.url.should == 'http://www.etsy.com?foo=bar&oauth_consumer_key=secret'
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
@@ -1,21 +1,102 @@
1
- require File.dirname(__FILE__) + '/../test_helper'
1
+ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  class EtsyTest < Test::Unit::TestCase
4
4
 
5
- describe "The Etsy module" do
6
-
7
- it "should be able to set and retrieve the API key" do
5
+ context "The Etsy module" do
6
+ setup do
7
+ Etsy.instance_variable_set(:@environment, nil)
8
+ Etsy.instance_variable_set(:@access_mode, nil)
9
+ Etsy.instance_variable_set(:@callback_url, nil)
10
+ Etsy.instance_variable_set(:@api_key, nil)
11
+ Etsy.instance_variable_set(:@api_secret, nil)
12
+ end
13
+
14
+ should "be able to set and retrieve the API key" do
8
15
  Etsy.api_key = 'key'
9
16
  Etsy.api_key.should == 'key'
10
17
  end
11
-
12
- it "should be able to find a user by username" do
18
+
19
+ should "be able to find a user by username" do
13
20
  user = stub()
14
-
15
- Etsy::User.expects(:find_by_username).with('littletjane').returns(user)
21
+
22
+ Etsy::User.expects(:find).with('littletjane').returns(user)
16
23
  Etsy.user('littletjane').should == user
17
24
  end
18
-
25
+
26
+ should "use the sandbox environment by default" do
27
+ Etsy.environment.should == :sandbox
28
+ end
29
+
30
+ should "be able to set the environment to a valid value" do
31
+ Etsy.environment = :production
32
+ Etsy.environment.should == :production
33
+ end
34
+
35
+ should "raise an exception when attempting to set an invalid environment" do
36
+ lambda { Etsy.environment = :invalid }.should raise_error(ArgumentError)
37
+ end
38
+
39
+ should "be able to set and retrieve the API secret" do
40
+ Etsy.api_secret = 'secret'
41
+ Etsy.api_secret.should == 'secret'
42
+ end
43
+
44
+ should "be in read-mode by default" do
45
+ Etsy.access_mode.should == :read_only
46
+ end
47
+
48
+ should "be able to set the access mode to a read-write" do
49
+ Etsy.access_mode = :read_write
50
+ Etsy.access_mode.should == :read_write
51
+ end
52
+
53
+ should "raise an exception when attempting to set an invalid access mode" do
54
+ lambda { Etsy.access_mode = :invalid }.should raise_error(ArgumentError)
55
+ end
56
+
57
+ should "be able to set the callback url" do
58
+ Etsy.callback_url = 'http://localhost'
59
+ Etsy.callback_url.should == 'http://localhost'
60
+ end
61
+
62
+ should "default callback to out-of-band" do
63
+ Etsy.callback_url.should == 'oob'
64
+ end
65
+ end
66
+
67
+ context "The Etsy module when set up properly" do
68
+ setup do
69
+ Etsy.instance_variable_set(:@environment, :sandbox)
70
+ Etsy.instance_variable_set(:@access_mode, :read_write)
71
+ Etsy.instance_variable_set(:@api_key, 'key')
72
+ Etsy.instance_variable_set(:@api_secret, 'secret')
73
+ Etsy.instance_variable_set(:@verification_request, nil)
74
+ end
75
+
76
+ should "provide a request token" do
77
+ request = stub(:request_token => 'token')
78
+ Etsy::VerificationRequest.stubs(:new).returns(request)
79
+
80
+ Etsy.request_token.should == 'token'
81
+ end
82
+
83
+ should "be able to generate an access token" do
84
+ Etsy::SecureClient.stubs(:new).with({
85
+ :request_token => 'toke',
86
+ :request_secret => 'secret',
87
+ :verifier => 'verifier'
88
+ }).returns(stub(:client => 'token'))
89
+
90
+ Etsy.access_token('toke', 'secret', 'verifier').should == 'token'
91
+ end
92
+
93
+ should "provide a verification URL" do
94
+ request = stub(:url => 'url')
95
+ Etsy::VerificationRequest.stubs(:new).returns(request)
96
+
97
+ Etsy.verification_url.should == 'url'
98
+ end
99
+
19
100
  end
20
101
 
21
- end
102
+ end
metadata CHANGED
@@ -1,7 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etsy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
5
11
  platform: ruby
6
12
  authors:
7
13
  - Patrick Reagan
@@ -9,19 +15,41 @@ autorequire:
9
15
  bindir: bin
10
16
  cert_chain: []
11
17
 
12
- date: 2009-05-04 00:00:00 -04:00
18
+ date: 2010-11-11 00:00:00 -07:00
13
19
  default_executable:
14
20
  dependencies:
15
21
  - !ruby/object:Gem::Dependency
16
22
  name: json
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ hash: 7
30
+ segments:
31
+ - 1
32
+ - 4
33
+ - 0
34
+ version: 1.4.0
17
35
  type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
36
+ version_requirements: *id001
37
+ - !ruby/object:Gem::Dependency
38
+ name: oauth
39
+ prerelease: false
40
+ requirement: &id002 !ruby/object:Gem::Requirement
41
+ none: false
20
42
  requirements:
21
43
  - - ~>
22
44
  - !ruby/object:Gem::Version
23
- version: 1.1.0
24
- version:
45
+ hash: 15
46
+ segments:
47
+ - 0
48
+ - 4
49
+ - 0
50
+ version: 0.4.0
51
+ type: :runtime
52
+ version_requirements: *id002
25
53
  description:
26
54
  email: reaganpr@gmail.com
27
55
  executables: []
@@ -33,32 +61,42 @@ extra_rdoc_files:
33
61
  files:
34
62
  - README.rdoc
35
63
  - Rakefile
36
- - lib/etsy
64
+ - lib/etsy/basic_client.rb
37
65
  - lib/etsy/image.rb
38
66
  - lib/etsy/listing.rb
39
67
  - lib/etsy/model.rb
40
68
  - lib/etsy/request.rb
41
69
  - lib/etsy/response.rb
70
+ - lib/etsy/secure_client.rb
42
71
  - lib/etsy/shop.rb
43
72
  - lib/etsy/user.rb
73
+ - lib/etsy/verification_request.rb
44
74
  - lib/etsy/version.rb
45
75
  - lib/etsy.rb
46
- - test/fixtures
47
- - test/fixtures/getShopDetails.json
48
- - test/fixtures/getShopListings.json
49
- - test/fixtures/getUserDetails.json
76
+ - test/fixtures/image/findAllListingImages.json
77
+ - test/fixtures/listing/findAllShopListingsActive.json
78
+ - test/fixtures/shop/findAllShop.json
79
+ - test/fixtures/shop/findAllShop.single.json
80
+ - test/fixtures/shop/getShop.multiple.json
81
+ - test/fixtures/shop/getShop.single.json
82
+ - test/fixtures/user/getUser.multiple.json
83
+ - test/fixtures/user/getUser.single.json
84
+ - test/fixtures/user/getUser.single.private.json
50
85
  - test/test_helper.rb
51
- - test/unit
52
- - test/unit/etsy
86
+ - test/unit/etsy/basic_client_test.rb
53
87
  - test/unit/etsy/image_test.rb
54
88
  - test/unit/etsy/listing_test.rb
55
89
  - test/unit/etsy/request_test.rb
56
90
  - test/unit/etsy/response_test.rb
91
+ - test/unit/etsy/secure_client_test.rb
57
92
  - test/unit/etsy/shop_test.rb
58
93
  - test/unit/etsy/user_test.rb
94
+ - test/unit/etsy/verification_request_test.rb
59
95
  - test/unit/etsy_test.rb
60
96
  has_rdoc: true
61
97
  homepage: http://sneaq.net
98
+ licenses: []
99
+
62
100
  post_install_message:
63
101
  rdoc_options:
64
102
  - --main
@@ -66,23 +104,29 @@ rdoc_options:
66
104
  require_paths:
67
105
  - lib
68
106
  required_ruby_version: !ruby/object:Gem::Requirement
107
+ none: false
69
108
  requirements:
70
109
  - - ">="
71
110
  - !ruby/object:Gem::Version
111
+ hash: 3
112
+ segments:
113
+ - 0
72
114
  version: "0"
73
- version:
74
115
  required_rubygems_version: !ruby/object:Gem::Requirement
116
+ none: false
75
117
  requirements:
76
118
  - - ">="
77
119
  - !ruby/object:Gem::Version
120
+ hash: 3
121
+ segments:
122
+ - 0
78
123
  version: "0"
79
- version:
80
124
  requirements: []
81
125
 
82
126
  rubyforge_project:
83
- rubygems_version: 1.3.1
127
+ rubygems_version: 1.3.7
84
128
  signing_key:
85
- specification_version: 2
129
+ specification_version: 3
86
130
  summary: Provides a friendly ruby-like interface to the Etsy API
87
131
  test_files: []
88
132