cardmagic-etsy 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.travis.yml +13 -0
  4. data/Gemfile +11 -0
  5. data/LICENSE +9 -0
  6. data/README.md +348 -0
  7. data/Rakefile +12 -0
  8. data/etsy.gemspec +34 -0
  9. data/lib/etsy.rb +223 -0
  10. data/lib/etsy/about.rb +15 -0
  11. data/lib/etsy/address.rb +47 -0
  12. data/lib/etsy/attribute_value.rb +46 -0
  13. data/lib/etsy/basic_client.rb +32 -0
  14. data/lib/etsy/category.rb +84 -0
  15. data/lib/etsy/country.rb +27 -0
  16. data/lib/etsy/favorite_listing.rb +26 -0
  17. data/lib/etsy/image.rb +44 -0
  18. data/lib/etsy/listing.rb +296 -0
  19. data/lib/etsy/model.rb +127 -0
  20. data/lib/etsy/payment_template.rb +33 -0
  21. data/lib/etsy/profile.rb +49 -0
  22. data/lib/etsy/receipt.rb +37 -0
  23. data/lib/etsy/request.rb +150 -0
  24. data/lib/etsy/response.rb +128 -0
  25. data/lib/etsy/section.rb +16 -0
  26. data/lib/etsy/secure_client.rb +131 -0
  27. data/lib/etsy/shipping_info.rb +27 -0
  28. data/lib/etsy/shipping_template.rb +41 -0
  29. data/lib/etsy/shop.rb +88 -0
  30. data/lib/etsy/transaction.rb +29 -0
  31. data/lib/etsy/user.rb +109 -0
  32. data/lib/etsy/variation/property_set.rb +71 -0
  33. data/lib/etsy/verification_request.rb +17 -0
  34. data/lib/etsy/version.rb +3 -0
  35. data/test/fixtures/about/getAbout.json +16 -0
  36. data/test/fixtures/address/getUserAddresses.json +12 -0
  37. data/test/fixtures/attribute_value/findAllListingPropertyValues.json +44 -0
  38. data/test/fixtures/category/findAllSubCategoryChildren.json +78 -0
  39. data/test/fixtures/category/findAllTopCategory.json +347 -0
  40. data/test/fixtures/category/findAllTopCategory.single.json +18 -0
  41. data/test/fixtures/category/findAllTopCategoryChildren.json +308 -0
  42. data/test/fixtures/category/getCategory.multiple.json +28 -0
  43. data/test/fixtures/category/getCategory.single.json +18 -0
  44. data/test/fixtures/country/getCountry.json +1 -0
  45. data/test/fixtures/favorite_listing/findAllFavoriteListings.json +1 -0
  46. data/test/fixtures/image/findAllListingImages.json +102 -0
  47. data/test/fixtures/listing/findAllListingActive.category.json +827 -0
  48. data/test/fixtures/listing/findAllShopListings.json +69 -0
  49. data/test/fixtures/listing/getListing.multiple.json +1 -0
  50. data/test/fixtures/listing/getListing.single.includeImages.json +1 -0
  51. data/test/fixtures/listing/getListing.single.json +1 -0
  52. data/test/fixtures/payment_template/getPaymentTemplate.json +1 -0
  53. data/test/fixtures/profile/new.json +28 -0
  54. data/test/fixtures/receipt/findAllShopReceipts.json +28 -0
  55. data/test/fixtures/section/getShopSection.json +18 -0
  56. data/test/fixtures/shipping_info/getShippingInfo.json +1 -0
  57. data/test/fixtures/shipping_template/getShippingTemplate.json +1 -0
  58. data/test/fixtures/shop/findAllShop.json +1 -0
  59. data/test/fixtures/shop/findAllShop.single.json +1 -0
  60. data/test/fixtures/shop/getShop.multiple.json +1 -0
  61. data/test/fixtures/shop/getShop.single.json +34 -0
  62. data/test/fixtures/transaction/findAllShopTransactions.json +1 -0
  63. data/test/fixtures/user/getUser.multiple.json +29 -0
  64. data/test/fixtures/user/getUser.single.json +13 -0
  65. data/test/fixtures/user/getUser.single.private.json +18 -0
  66. data/test/fixtures/user/getUser.single.withProfile.json +38 -0
  67. data/test/fixtures/user/getUser.single.withShops.json +41 -0
  68. data/test/test_helper.rb +45 -0
  69. data/test/unit/etsy/address_test.rb +61 -0
  70. data/test/unit/etsy/attribute_value_test.rb +67 -0
  71. data/test/unit/etsy/basic_client_test.rb +30 -0
  72. data/test/unit/etsy/category_test.rb +106 -0
  73. data/test/unit/etsy/country_test.rb +64 -0
  74. data/test/unit/etsy/favorite_listing_test.rb +44 -0
  75. data/test/unit/etsy/image_test.rb +51 -0
  76. data/test/unit/etsy/listing_test.rb +268 -0
  77. data/test/unit/etsy/model_test.rb +64 -0
  78. data/test/unit/etsy/payment_template_test.rb +68 -0
  79. data/test/unit/etsy/profile_test.rb +111 -0
  80. data/test/unit/etsy/receipt_test.rb +107 -0
  81. data/test/unit/etsy/request_test.rb +190 -0
  82. data/test/unit/etsy/response_test.rb +175 -0
  83. data/test/unit/etsy/section_test.rb +28 -0
  84. data/test/unit/etsy/secure_client_test.rb +132 -0
  85. data/test/unit/etsy/shipping_info_test.rb +24 -0
  86. data/test/unit/etsy/shipping_template_test.rb +24 -0
  87. data/test/unit/etsy/shop_about_test.rb +43 -0
  88. data/test/unit/etsy/shop_test.rb +116 -0
  89. data/test/unit/etsy/transaction_test.rb +61 -0
  90. data/test/unit/etsy/user_test.rb +250 -0
  91. data/test/unit/etsy/verification_request_test.rb +26 -0
  92. data/test/unit/etsy_test.rb +173 -0
  93. metadata +293 -0
@@ -0,0 +1,64 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ module Etsy
4
+ class TestModel
5
+ include Etsy::Model
6
+ end
7
+
8
+ class ModelTest < Test::Unit::TestCase
9
+
10
+ def mock_empty_request(options = {})
11
+ body = options.delete(:body) { '{}' }
12
+ Request.expects(:new).with('', options).returns(stub(:get => stub(:body => body, :code => 200)))
13
+ end
14
+
15
+ context 'An instance of a Model' do
16
+
17
+ should 'perform no requests if :limit is 0' do
18
+ Request.expects(:new).never
19
+ TestModel.get_all('', :limit => 0)
20
+ end
21
+
22
+ should 'perform only one request if :limit is less than 100' do
23
+ mock_empty_request(:limit => 10, :offset => 0).once
24
+ TestModel.get_all('', :limit => 10)
25
+ end
26
+
27
+ should 'perform only one request if :limit is equal to 100' do
28
+ mock_empty_request(:limit => 100, :offset => 0).once
29
+ TestModel.get_all('', :limit => 100)
30
+ end
31
+
32
+ should 'perform multiple requests if :limit is greater than 100' do
33
+ body = '{"count": 150, "pagination":{}}'
34
+ mock_empty_request(:limit => 100, :offset => 0, :body => body).once
35
+ mock_empty_request(:limit => 50, :offset => 100, :body => body).once
36
+ TestModel.get_all('', :limit => 150)
37
+ end
38
+
39
+ should 'perform only one request if :limit is :all and count is less than 100' do
40
+ mock_empty_request(:limit => 100, :offset => 0, :body => '{"count": 10}').once
41
+ TestModel.get_all('', :limit => :all)
42
+ end
43
+
44
+ should 'perform only one request if :limit is :all and count is equal to 100' do
45
+ mock_empty_request(:limit => 100, :offset => 0, :body => '{"count": 100}').once
46
+ TestModel.get_all('', :limit => :all)
47
+ end
48
+
49
+ should 'perform only one request if :limit is :all and :offset is greater than count' do
50
+ mock_empty_request(:limit => 100, :offset => 40, :body => '{"count": 25}').once
51
+ TestModel.get_all('', :limit => :all, :offset => 40)
52
+ end
53
+
54
+ should 'perform multiple requests if :limit is :all and count is greater than 100' do
55
+ body = '{"count": 210, "pagination": {}}'
56
+ mock_empty_request(:limit => 100, :offset => 0, :body => body).once
57
+ mock_empty_request(:limit => 100, :offset => 100, :body => body).once
58
+ mock_empty_request(:limit => 10, :offset => 200, :body => body).once
59
+
60
+ TestModel.get_all('', :limit => :all)
61
+ end
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,68 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ module Etsy
4
+ class PaymentTemplateTest < Test::Unit::TestCase
5
+ context "An instance of the PaymentTemplate class" do
6
+ setup do
7
+ data = read_fixture('payment_template/getPaymentTemplate.json')
8
+ @payment_template = PaymentTemplate.new(data.first)
9
+ end
10
+
11
+ should "have an id" do
12
+ @payment_template.id.should == 51
13
+ end
14
+
15
+ should "have attribute: allow_check" do
16
+ @payment_template.allow_check.should == false
17
+ end
18
+
19
+ should "have attribute: allow_mo" do
20
+ @payment_template.allow_mo.should == false
21
+ end
22
+
23
+ should "have attribute: allow_other" do
24
+ @payment_template.allow_other.should == true
25
+ end
26
+
27
+ should "have attribute: allow_paypal" do
28
+ @payment_template.allow_paypal.should == true
29
+ end
30
+
31
+ should "have attribute: allow_cc" do
32
+ @payment_template.allow_cc.should == false
33
+ end
34
+
35
+ should "have attribute: paypal_email" do
36
+ @payment_template.paypal_email.should == "user@example.com"
37
+ end
38
+
39
+ should "have attribute: name" do
40
+ @payment_template.name.should == "Example Template"
41
+ end
42
+
43
+ should "have attribute: first_line" do
44
+ @payment_template.first_line.should == nil
45
+ end
46
+
47
+ should "have attribute: second_line" do
48
+ @payment_template.second_line.should == nil
49
+ end
50
+
51
+ should "have attribute: city" do
52
+ @payment_template.city.should == "Chicago"
53
+ end
54
+
55
+ should "have attribute: state" do
56
+ @payment_template.state.should == "IL"
57
+ end
58
+
59
+ should "have attribute: zip" do
60
+ @payment_template.zip.should == "60605"
61
+ end
62
+
63
+ should "have attribute: country_id" do
64
+ @payment_template.country_id.should == 4
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,111 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ module Etsy
4
+ class ProfileTest < Test::Unit::TestCase
5
+
6
+ # The Etsy profile can only be accessed as an association through other resources.
7
+ # There are no finders.
8
+ context "An instance of the Profile class" do
9
+
10
+ context "with response data" do
11
+ setup do
12
+ data = read_fixture('profile/new.json')
13
+ @profile = Profile.new(data)
14
+ end
15
+
16
+ should "have a value for :id" do
17
+ @profile.id.should == 123
18
+ end
19
+
20
+ should "have a value for :user_id" do
21
+ @profile.user_id.should == 5327518
22
+ end
23
+
24
+ should "have a value for :username" do
25
+ @profile.username.should == "littletjane"
26
+ end
27
+
28
+ should "have a value for :bio" do
29
+ @profile.bio.should == "I make stuff"
30
+ end
31
+
32
+ should "have a value for :gender" do
33
+ @profile.gender.should == "female"
34
+ end
35
+
36
+ should "have a value for :birth_day" do
37
+ @profile.birth_day.should == "01"
38
+ end
39
+
40
+ should "have a value for :birth_month" do
41
+ @profile.birth_month.should == "01"
42
+ end
43
+
44
+ should "have a value for :birth_year" do
45
+ @profile.birth_year.should == "1970"
46
+ end
47
+
48
+ should "have a value for :joined_at" do
49
+ @profile.joined_at.should == Time.at(1225392413)
50
+ end
51
+
52
+ should "have a value for :materials" do
53
+ @profile.materials.should == []
54
+ end
55
+
56
+ should "have a value for :country_id" do
57
+ @profile.country_id.should == 209
58
+ end
59
+
60
+ should "have a value for :city" do
61
+ @profile.city.should == "BigCity"
62
+ end
63
+
64
+ should "have a value for :avatar_id" do
65
+ @profile.avatar_id.should == 345
66
+ end
67
+
68
+ should "have a value for :location" do
69
+ @profile.location.should == "HQ"
70
+ end
71
+
72
+ should "have a value for :region" do
73
+ @profile.region.should == "The Desert"
74
+ end
75
+
76
+ should "have a value for :lat" do
77
+ @profile.lat.should == 39.5304
78
+ end
79
+
80
+ should "have a value for :lon" do
81
+ @profile.lon.should == -119.8144
82
+ end
83
+
84
+ should "have a value for :transaction_buy_count" do
85
+ @profile.transaction_buy_count.should == 19
86
+ end
87
+
88
+ should "have a value for :transaction_sold_count" do
89
+ @profile.transaction_sold_count.should == 16
90
+ end
91
+
92
+ should "have a value for :seller?" do
93
+ @profile.seller?.should == true
94
+ end
95
+
96
+ should "have a value for :image" do
97
+ @profile.image.should == 'some_image.jpg'
98
+ end
99
+
100
+ should "have a value for :first_name" do
101
+ @profile.first_name.should == 'Tinker'
102
+ end
103
+
104
+ should "have a value for :last_name" do
105
+ @profile.last_name.should == 'Bell'
106
+ end
107
+ end
108
+
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,107 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ module Etsy
4
+ class ReceiptTest < Test::Unit::TestCase
5
+
6
+ context "The Receipt class" do
7
+
8
+ should "be able to find receipts for a shop" do
9
+ receipts = mock_request('/shops/1/receipts', {'key' => 'value'}, 'Receipt', 'findAllShopReceipts.json')
10
+ Receipt.find_all_by_shop_id(1, {'key' => 'value'}).should == receipts
11
+ end
12
+
13
+ should "be able to find receipts for a shop that also have a given status" do
14
+ receipts = mock_request('/shops/1/receipts/open', {'key' => 'value'}, 'Receipt', 'findAllShopReceipts.json')
15
+ Receipt.find_all_by_shop_id_and_status(1, 'open', {'key' => 'value'}).should == receipts
16
+ end
17
+
18
+ end
19
+
20
+ context "An instance of the Receipt class" do
21
+
22
+ context "with response data" do
23
+ setup do
24
+ data = read_fixture('receipt/findAllShopReceipts.json')
25
+ @receipt = Receipt.new(data.first)
26
+ end
27
+
28
+ should "have a value for :id" do
29
+ @receipt.id.should == 27230877
30
+ end
31
+
32
+ should "have :buyer_id" do
33
+ @receipt.buyer_id.should == 12345
34
+ end
35
+
36
+ should "have :created_at" do
37
+ @receipt.created_at.should == Time.at(1412206858)
38
+ end
39
+
40
+ should "have a value for :quantity" do
41
+ @receipt.quantity.should == 5
42
+ end
43
+
44
+ should "have a value for :listing_id" do
45
+ @receipt.listing_id.should == 123456
46
+ end
47
+
48
+ should "have a value for name" do
49
+ @receipt.name.should == "Mike Taylor"
50
+ end
51
+
52
+ should "have a value for first_line" do
53
+ @receipt.first_line.should == "123 Fun St"
54
+ end
55
+
56
+ should "have a value for second_line" do
57
+ @receipt.second_line.should == "#3b"
58
+ end
59
+
60
+ should "have a value for city" do
61
+ @receipt.city.should == "San Francisco"
62
+ end
63
+
64
+ should "have a value for state" do
65
+ @receipt.state.should == "CA"
66
+ end
67
+
68
+ should "have a value for zip" do
69
+ @receipt.zip.should == "94501"
70
+ end
71
+
72
+ should "have a value for country_id" do
73
+ @receipt.country_id.should == 201
74
+ end
75
+
76
+ should "have a value for payment_email" do
77
+ @receipt.payment_email.should == "foo@example.com"
78
+ end
79
+
80
+ should "have a value for buyer_email" do
81
+ @receipt.buyer_email.should == "bar@example.com"
82
+ end
83
+ end
84
+
85
+ should "know the buyer" do
86
+ User.stubs(:find).with(1).returns('user')
87
+
88
+ receipt = Receipt.new
89
+ receipt.stubs(:buyer_id).with().returns(1)
90
+
91
+ receipt.buyer.should == 'user'
92
+ end
93
+
94
+ should "have transaction information" do
95
+ Transaction.stubs(:find_all_by_receipt_id).with(1, {:access_token=>'token',:access_secret=>'secret'}).returns('transactions')
96
+
97
+ receipt = Receipt.new
98
+ receipt.stubs(:id).with().returns(1)
99
+ receipt.stubs(:token).with().returns('token')
100
+ receipt.stubs(:secret).with().returns('secret')
101
+
102
+ receipt.transactions.should == 'transactions'
103
+ end
104
+ end
105
+
106
+ end
107
+ end
@@ -0,0 +1,190 @@
1
+ require File.expand_path('../../../test_helper', __FILE__)
2
+
3
+ module Etsy
4
+ class RequestTest < Test::Unit::TestCase
5
+
6
+ context "The Request class" do
7
+
8
+ should "be able to retrieve a response" do
9
+ http_response = stub()
10
+ response = stub()
11
+
12
+ Response.expects(:new).with(http_response).returns(response)
13
+
14
+ request = mock {|m| m.expects(:get).with().returns(http_response) }
15
+ Request.expects(:new).with('/user', :one => 'two').returns(request)
16
+
17
+ Request.get('/user', :one => 'two').should == response
18
+ end
19
+
20
+ should "require OAuth credentials if :require_secure is set" do
21
+ lambda do
22
+ Request.new('/path', :require_secure => true)
23
+ end.should raise_error(/Secure connection required/)
24
+ end
25
+ end
26
+
27
+ context "An instance of the Request class" do
28
+
29
+ should "know the base path" do
30
+ Request.new('').base_path.should == '/v2'
31
+ end
32
+
33
+ should "append the api_key to the parameters in basic mode" do
34
+ Etsy.expects(:api_key).with().returns('key')
35
+ Request.stubs(:secure?).returns(false)
36
+
37
+ r = Request.new('/user', :limit => '1')
38
+ r.parameters.should == {:limit => '1', :api_key => 'key'}
39
+ end
40
+
41
+ should "not append the api_key to the parameters in secure mode" do
42
+ Etsy.stubs(:access_mode).returns(:authenticated)
43
+
44
+ r = Request.new('/user', :limit => '1', :access_token => 'token', :access_secret => 'secret')
45
+ r.parameters.should == {:limit => '1'}
46
+ end
47
+
48
+
49
+ should "be able to generate query parameters" do
50
+ r = Request.new('/user')
51
+ r.expects(:parameters).with().returns(:api_key => 'foo')
52
+ r.query.should == 'api_key=foo'
53
+ end
54
+
55
+ should "be able to join multiple query parameters" do
56
+ params = {:limit => '1', :other => 'yes'}
57
+
58
+ r = Request.new('/user', params)
59
+ r.stubs(:parameters).with().returns(params)
60
+
61
+ r.query.split('&').sort.should == %w(limit=1 other=yes)
62
+ end
63
+
64
+ should "be able to request a single association" do
65
+ r = Request.new('/foo', {:includes => 'Thunder'})
66
+ r.stubs(:parameters).with().returns({:a => :b})
67
+ CGI.parse(r.query).should == { "a" => ["b"], "includes" => ["Thunder"] }
68
+ end
69
+
70
+ should "be able make simplified association requests" do
71
+ r = Request.new('/foo', {:includes => ['Thunder', 'Lightning']})
72
+ r.stubs(:parameters).with().returns({:a => :b})
73
+ CGI.parse(r.query).should == { "a" => ["b"], "includes" => ["Thunder,Lightning"] }
74
+ end
75
+
76
+ should "be able to generate detailed association queries" do
77
+ r = Request.new('/foo')
78
+ r.association(:resource => 'Lightning').should == 'Lightning'
79
+ end
80
+
81
+ should "be able to specify fields in association query" do
82
+ r = Request.new('/foo')
83
+ params = {:resource => 'Lightning', :fields => ['one', 'two']}
84
+ r.association(params).should == 'Lightning(one,two)'
85
+ end
86
+
87
+ should "be able to specify limit in association query" do
88
+ r = Request.new('/foo')
89
+ params = {:resource => 'Lightning', :limit => 3}
90
+ r.association(params).should == 'Lightning:3:0'
91
+ end
92
+
93
+ should "be able to specify offset in association query" do
94
+ r = Request.new('/foo')
95
+ params = {:resource => 'Lightning', :offset => 7}
96
+ r.association(params).should == 'Lightning:25:7'
97
+ end
98
+
99
+ should "be able to join multiple resources in association query" do
100
+ params = {
101
+ :a => 'b',
102
+ :includes => [
103
+ {:resource => 'Lightning'},
104
+ {:resource => 'Thunder'}
105
+ ]
106
+ }
107
+ r = Request.new('/foo', params)
108
+ r.stubs(:base_path).with().returns('/base')
109
+ r.stubs(:parameters).with().returns(:a => 'b')
110
+ uri = URI.parse(r.endpoint_url)
111
+ uri.path.should == '/base/foo'
112
+ CGI.parse(uri.query).should == { "a" => ["b"], "includes" => ["Lightning,Thunder"] }
113
+ end
114
+
115
+ should "be able to determine the endpoint URI when in read-only mode" do
116
+ r = Request.new('/user')
117
+ r.stubs(:base_path).with().returns('/base')
118
+ r.stubs(:query).with().returns('a=b')
119
+
120
+ r.endpoint_url.should == '/base/user?a=b'
121
+ end
122
+
123
+ should "be able to determine the endpoint URI when in authenticated mode" do
124
+ Etsy.stubs(:access_mode).returns(:authenticated)
125
+
126
+ r = Request.new('/user', :access_token => 'toke', :access_secret => 'secret')
127
+ r.stubs(:base_path).with().returns('/base')
128
+ r.stubs(:query).with().returns('a=b')
129
+
130
+ r.endpoint_url.should == '/base/user?a=b'
131
+ end
132
+
133
+ should "know the client for read-only mode" do
134
+ Etsy.stubs(:access_mode).returns(:read_only)
135
+
136
+ BasicClient.stubs(:new).returns 'client'
137
+
138
+ r = Request.new('')
139
+
140
+ r.client.should == 'client'
141
+ end
142
+
143
+ should "know the client for authenticated mode when there is no access token information" do
144
+ Etsy.stubs(:access_mode).returns(:authenticated)
145
+
146
+ BasicClient.stubs(:new).returns 'client'
147
+
148
+ r = Request.new('')
149
+
150
+ r.client.should == 'client'
151
+ end
152
+
153
+ should "know the client for authenticated mode when there is access token information" do
154
+ Etsy.stubs(:access_mode).returns(:authenticated)
155
+ SecureClient.stubs(:new).with(:access_token => 'toke', :access_secret => 'secret').returns('client')
156
+
157
+ r = Request.new('', :access_token => 'toke', :access_secret => 'secret')
158
+ r.client.should == 'client'
159
+ end
160
+
161
+ should "be able to make a successful request" do
162
+ client = stub()
163
+ client.stubs(:get).with('endpoint_url').returns('response')
164
+
165
+ r = Request.new('/user')
166
+ r.stubs(:endpoint_url).with().returns('endpoint_url')
167
+ r.stubs(:client).returns(client)
168
+
169
+ r.get.should == 'response'
170
+ end
171
+
172
+ should "not modify the options hash passed to it" do
173
+ options = { :includes => 'Lightning',
174
+ :access_token => 'token',
175
+ :access_secret => 'secret',
176
+ :fields => [:id],
177
+ :limit => 100,
178
+ :offset => 100 }
179
+ options_copy = options.dup
180
+
181
+ Request.new('', options)
182
+
183
+ options.should == options_copy
184
+ end
185
+
186
+ end
187
+
188
+
189
+ end
190
+ end