crystal_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +17 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +4 -0
  5. data/Guardfile +7 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +50 -0
  8. data/Rakefile +1 -0
  9. data/crystal_api.gemspec +34 -0
  10. data/lib/crystal_api.rb +51 -0
  11. data/lib/crystal_api/attributes.rb +210 -0
  12. data/lib/crystal_api/category.rb +28 -0
  13. data/lib/crystal_api/descriptor.rb +11 -0
  14. data/lib/crystal_api/error_response.rb +17 -0
  15. data/lib/crystal_api/errors.rb +8 -0
  16. data/lib/crystal_api/hmac_request_signing.rb +40 -0
  17. data/lib/crystal_api/market_prices.rb +11 -0
  18. data/lib/crystal_api/message_verifier.rb +26 -0
  19. data/lib/crystal_api/money.rb +8 -0
  20. data/lib/crystal_api/paginated_collection.rb +13 -0
  21. data/lib/crystal_api/photo.rb +10 -0
  22. data/lib/crystal_api/product.rb +55 -0
  23. data/lib/crystal_api/product_descriptor.rb +10 -0
  24. data/lib/crystal_api/received_webhook_parser.rb +17 -0
  25. data/lib/crystal_api/report.rb +17 -0
  26. data/lib/crystal_api/store.rb +10 -0
  27. data/lib/crystal_api/store_endpoint.rb +82 -0
  28. data/lib/crystal_api/store_prefs.rb +54 -0
  29. data/lib/crystal_api/url.rb +9 -0
  30. data/lib/crystal_api/variant.rb +28 -0
  31. data/lib/crystal_api/variant_descriptor.rb +10 -0
  32. data/lib/crystal_api/version.rb +3 -0
  33. data/lib/crystal_api/webhook.rb +15 -0
  34. data/lib/crystal_api/webhook_envelope.rb +12 -0
  35. data/lib/crystal_api/webhook_registration.rb +34 -0
  36. data/lib/crystal_api/webhook_verifier.rb +20 -0
  37. data/spec/cassettes/CrystalApi_StoreEndpoint/_get/prefs/store/makes_the_request_to_the_endpoint.yml +67 -0
  38. data/spec/cassettes/CrystalApi_StoreEndpoint/_get/prefs/store/parses_the_returned_a_store_pref.yml +67 -0
  39. data/spec/cassettes/CrystalApi_StoreEndpoint/_get/prefs/store/returns_a_store_pref_instance.yml +67 -0
  40. data/spec/crystal_api/attributes_spec.rb +7 -0
  41. data/spec/crystal_api/category_spec.rb +112 -0
  42. data/spec/crystal_api/money_spec.rb +10 -0
  43. data/spec/crystal_api/paginated_collection_spec.rb +31 -0
  44. data/spec/crystal_api/photo_spec.rb +41 -0
  45. data/spec/crystal_api/product_spec.rb +209 -0
  46. data/spec/crystal_api/received_webhook_parser_spec.rb +23 -0
  47. data/spec/crystal_api/report_spec.rb +33 -0
  48. data/spec/crystal_api/store_endpoint_spec.rb +37 -0
  49. data/spec/crystal_api/store_prefs_spec.rb +119 -0
  50. data/spec/crystal_api/store_spec.rb +17 -0
  51. data/spec/crystal_api/variant_descriptor_spec.rb +16 -0
  52. data/spec/crystal_api/variant_spec.rb +85 -0
  53. data/spec/crystal_api/webhook_envelope_spec.rb +45 -0
  54. data/spec/crystal_api/webhook_registration_spec.rb +129 -0
  55. data/spec/crystal_api/webhook_spec.rb +54 -0
  56. data/spec/spec_helper.rb +25 -0
  57. data/spec/support/attribute_examples.rb +77 -0
  58. data/spec/support/vcr.rb +7 -0
  59. metadata +305 -0
@@ -0,0 +1,10 @@
1
+ module CrystalApi
2
+ class VariantDescriptor
3
+ include Attributes
4
+
5
+ root_element :variant_descriptor
6
+
7
+ string_attribute :name
8
+ string_attribute :value
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module CrystalApi
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,15 @@
1
+ module CrystalApi
2
+ class Webhook
3
+ include Attributes
4
+
5
+ root_element :webhook
6
+
7
+ integer_attribute :id
8
+ integer_attribute :resource_id
9
+
10
+ string_attribute :address
11
+ string_attribute :topic
12
+
13
+ boolean_attribute :only_catalog
14
+ end
15
+ end
@@ -0,0 +1,12 @@
1
+ module CrystalApi
2
+ class WebhookEnvelope
3
+ include Attributes
4
+
5
+ root_element :webhook_envelope
6
+
7
+ string_attribute :topic
8
+ string_attribute :store_name
9
+ integer_attribute :resource_id
10
+ attribute :payload
11
+ end
12
+ end
@@ -0,0 +1,34 @@
1
+ module CrystalApi
2
+ class WebhookRegistration
3
+ attr_reader :endpoint
4
+
5
+ def initialize(endpoint)
6
+ @endpoint = endpoint
7
+ end
8
+
9
+ def register(webhook)
10
+ endpoint.post('/webhooks', webhook.to_json(:except => [:id]))
11
+ end
12
+
13
+ def registered?(webhook)
14
+ registered_webhooks.any? {|wh| wh.address == webhook.address &&
15
+ wh.topic == webhook.topic &&
16
+ wh.resource_id == webhook.resource_id }
17
+ end
18
+
19
+ def deregister(webhook_id)
20
+ endpoint.delete("/webhooks/#{webhook_id}")
21
+ end
22
+
23
+ def registered_webhooks
24
+ endpoint.get('/webhooks').parsed
25
+ end
26
+
27
+ def webhook_id(webhook)
28
+ wh = registered_webhooks.detect {|wh| wh.address == webhook.address &&
29
+ wh.topic == webhook.topic &&
30
+ wh.resource_id == webhook.resource_id }
31
+ wh && wh.id
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,20 @@
1
+ module CrystalApi
2
+ class WebhookVerifier
3
+ include HmacRequestSigning
4
+
5
+ attr_reader :secret_signing_key, :request
6
+
7
+ def initialize(secret_signing_key, request)
8
+ @secret_signing_key = secret_signing_key
9
+ @request = request
10
+ end
11
+
12
+ def verified?
13
+ request_signature(request) == expected_signature
14
+ end
15
+
16
+ def expected_signature
17
+ hmac_sha256(secret_signing_key, request.raw_post)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,67 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:3000/api/v1/prefs/store
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Authorization:
15
+ - OAuth TOKEN
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: ! 'OK '
22
+ headers:
23
+ Etag:
24
+ - ! '"62dbdcce719c67de7a0eee8d9e92ea2c"'
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Content-Md5:
28
+ - 62dbdcce719c67de7a0eee8d9e92ea2c
29
+ Connection:
30
+ - Keep-Alive
31
+ Server:
32
+ - WEBrick/1.3.1 (Ruby/1.8.7/2012-02-08)
33
+ X-Runtime:
34
+ - '211'
35
+ Access-Control-Allow-Origin:
36
+ - ! '*'
37
+ Date:
38
+ - Thu, 24 Jan 2013 04:45:30 GMT
39
+ Cache-Control:
40
+ - private, max-age=0, must-revalidate
41
+ Content-Length:
42
+ - '2498'
43
+ Access-Control-Expose-Headers:
44
+ - content-type, content-md5, x-oauth-scopes, x-accepted-oauth-scopes, content-length,
45
+ cache-control
46
+ Access-Control-Allow-Methods:
47
+ - GET, POST, PUT, DELETE, OPTIONS
48
+ Access-Control-Allow-Headers:
49
+ - origin, authorization, content-type, accept
50
+ Set-Cookie:
51
+ - _admin_session=d7405de32bc2300e951a253d069ad71d; path=/; expires=Fri, 25-Jan-2013
52
+ 00:45:30 GMT; HttpOnly
53
+ body:
54
+ encoding: US-ASCII
55
+ string: ! '{"store_prefs":{"buylist_email":"donald@crystalcommerce.com","satisfaction_blurb":"Our
56
+ #1 goal is making sure you''re happy with your purchase today. Happy customers
57
+ come back soon and tell their friends. Its a win, win.","enable_frontend_auto_translate":false,"logo_photo":{"photo":{"is_default":false,"urls":{"large":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/large/arux-banner.png"},"medium":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/medium/arux-banner.png"},"original":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/arux-banner.png"},"huge":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/huge/arux-banner.png"},"thumb":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/thumb/arux-banner.png"}}}},"return_blurb":"If
58
+ your order ever arrives in less than expected condition, please promptly return
59
+ it to us for a full refund. We take your business with us very seriously.","time_zone":"Pacific
60
+ Time (US & Canada)","city":"Seattle","hostname":"store.arux.net","customer_service_phone":"555-555-5555","zip":"98125","sales_tax":"9","cancel":"14","default_currency_code":"USD","default_locale":"x-bork","privacy_blurb":"We
61
+ promise to never ever sell your personal private information to any 3rd party
62
+ company! We hate spam too. Order today with confidence.","enable_manual_credit_card_capture":false,"store_credit_multiplier":"1.3","buylist_cancel_days":"0","checkout_special_instructions":"","default_exchange_rate":"1","enable_buy_order_notifications":"1","enable_buylist":true,"enable_bcc_buylist_confirmation_emails":false,"enable_tax_on_shipping":true,"enable_sort_by_price":true,"feedback_timespan":"14","home_redirect":"/catalog/magic_singles-core_sets-magic_2012/306","phone":"555-555-5555","state":"WA","enable_referafriend":true,"address":"3400
63
+ NE 110th ST #B-1","payment":"7","contact_name":"Mr. Arux","name":"Arux Gaming
64
+ and Hobbies","display_customer_service_phone":false,"enable_order_notifications":"1","enable_account_approval":false,"enable_watermarking_of_product_photos":false,"watermark_photo":null,"country":"US","contact_email":"donald@crystalcommerce.com","buylist_reminder_days":"0","hide_bank_transfer_details_in_emails":false,"enable_invoice_logo":false}}'
65
+ http_version:
66
+ recorded_at: Thu, 24 Jan 2013 04:45:30 GMT
67
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,67 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:3000/api/v1/prefs/store
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Authorization:
15
+ - OAuth TOKEN
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: ! 'OK '
22
+ headers:
23
+ Etag:
24
+ - ! '"62dbdcce719c67de7a0eee8d9e92ea2c"'
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Content-Md5:
28
+ - 62dbdcce719c67de7a0eee8d9e92ea2c
29
+ Connection:
30
+ - Keep-Alive
31
+ Server:
32
+ - WEBrick/1.3.1 (Ruby/1.8.7/2012-02-08)
33
+ X-Runtime:
34
+ - '64'
35
+ Access-Control-Allow-Origin:
36
+ - ! '*'
37
+ Date:
38
+ - Thu, 24 Jan 2013 05:14:11 GMT
39
+ Cache-Control:
40
+ - private, max-age=0, must-revalidate
41
+ Content-Length:
42
+ - '2498'
43
+ Access-Control-Expose-Headers:
44
+ - content-type, content-md5, x-oauth-scopes, x-accepted-oauth-scopes, content-length,
45
+ cache-control
46
+ Access-Control-Allow-Methods:
47
+ - GET, POST, PUT, DELETE, OPTIONS
48
+ Access-Control-Allow-Headers:
49
+ - origin, authorization, content-type, accept
50
+ Set-Cookie:
51
+ - _admin_session=d989077369170dfdbfee1b5607371d27; path=/; expires=Fri, 25-Jan-2013
52
+ 01:14:11 GMT; HttpOnly
53
+ body:
54
+ encoding: US-ASCII
55
+ string: ! '{"store_prefs":{"buylist_email":"donald@crystalcommerce.com","satisfaction_blurb":"Our
56
+ #1 goal is making sure you''re happy with your purchase today. Happy customers
57
+ come back soon and tell their friends. Its a win, win.","enable_frontend_auto_translate":false,"logo_photo":{"photo":{"is_default":false,"urls":{"large":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/large/arux-banner.png"},"medium":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/medium/arux-banner.png"},"original":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/arux-banner.png"},"huge":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/huge/arux-banner.png"},"thumb":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/thumb/arux-banner.png"}}}},"return_blurb":"If
58
+ your order ever arrives in less than expected condition, please promptly return
59
+ it to us for a full refund. We take your business with us very seriously.","time_zone":"Pacific
60
+ Time (US & Canada)","city":"Seattle","hostname":"store.arux.net","customer_service_phone":"555-555-5555","zip":"98125","sales_tax":"9","cancel":"14","default_currency_code":"USD","default_locale":"x-bork","privacy_blurb":"We
61
+ promise to never ever sell your personal private information to any 3rd party
62
+ company! We hate spam too. Order today with confidence.","enable_manual_credit_card_capture":false,"store_credit_multiplier":"1.3","buylist_cancel_days":"0","checkout_special_instructions":"","default_exchange_rate":"1","enable_buy_order_notifications":"1","enable_buylist":true,"enable_bcc_buylist_confirmation_emails":false,"enable_tax_on_shipping":true,"enable_sort_by_price":true,"feedback_timespan":"14","home_redirect":"/catalog/magic_singles-core_sets-magic_2012/306","phone":"555-555-5555","state":"WA","enable_referafriend":true,"address":"3400
63
+ NE 110th ST #B-1","payment":"7","contact_name":"Mr. Arux","name":"Arux Gaming
64
+ and Hobbies","display_customer_service_phone":false,"enable_order_notifications":"1","enable_account_approval":false,"enable_watermarking_of_product_photos":false,"watermark_photo":null,"country":"US","contact_email":"donald@crystalcommerce.com","buylist_reminder_days":"0","hide_bank_transfer_details_in_emails":false,"enable_invoice_logo":false}}'
65
+ http_version:
66
+ recorded_at: Thu, 24 Jan 2013 05:14:11 GMT
67
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,67 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://localhost:3000/api/v1/prefs/store
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - ! '*/*; q=0.5, application/xml'
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Authorization:
15
+ - OAuth TOKEN
16
+ User-Agent:
17
+ - Ruby
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: ! 'OK '
22
+ headers:
23
+ Etag:
24
+ - ! '"62dbdcce719c67de7a0eee8d9e92ea2c"'
25
+ Content-Type:
26
+ - application/json; charset=utf-8
27
+ Content-Md5:
28
+ - 62dbdcce719c67de7a0eee8d9e92ea2c
29
+ Connection:
30
+ - Keep-Alive
31
+ Server:
32
+ - WEBrick/1.3.1 (Ruby/1.8.7/2012-02-08)
33
+ X-Runtime:
34
+ - '58'
35
+ Access-Control-Allow-Origin:
36
+ - ! '*'
37
+ Date:
38
+ - Thu, 24 Jan 2013 04:47:04 GMT
39
+ Cache-Control:
40
+ - private, max-age=0, must-revalidate
41
+ Content-Length:
42
+ - '2498'
43
+ Access-Control-Expose-Headers:
44
+ - content-type, content-md5, x-oauth-scopes, x-accepted-oauth-scopes, content-length,
45
+ cache-control
46
+ Access-Control-Allow-Methods:
47
+ - GET, POST, PUT, DELETE, OPTIONS
48
+ Access-Control-Allow-Headers:
49
+ - origin, authorization, content-type, accept
50
+ Set-Cookie:
51
+ - _admin_session=ebb621b076e457c5da22fb012b437686; path=/; expires=Fri, 25-Jan-2013
52
+ 00:47:04 GMT; HttpOnly
53
+ body:
54
+ encoding: US-ASCII
55
+ string: ! '{"store_prefs":{"buylist_email":"donald@crystalcommerce.com","satisfaction_blurb":"Our
56
+ #1 goal is making sure you''re happy with your purchase today. Happy customers
57
+ come back soon and tell their friends. Its a win, win.","enable_frontend_auto_translate":false,"logo_photo":{"photo":{"is_default":false,"urls":{"large":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/large/arux-banner.png"},"medium":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/medium/arux-banner.png"},"original":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/arux-banner.png"},"huge":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/huge/arux-banner.png"},"thumb":{"href":"http://crystalcommerce-development.s3.amazonaws.com/photo/arux/file/8e233b1f3da489341a9d55a1ca744556/thumb/arux-banner.png"}}}},"return_blurb":"If
58
+ your order ever arrives in less than expected condition, please promptly return
59
+ it to us for a full refund. We take your business with us very seriously.","time_zone":"Pacific
60
+ Time (US & Canada)","city":"Seattle","hostname":"store.arux.net","customer_service_phone":"555-555-5555","zip":"98125","sales_tax":"9","cancel":"14","default_currency_code":"USD","default_locale":"x-bork","privacy_blurb":"We
61
+ promise to never ever sell your personal private information to any 3rd party
62
+ company! We hate spam too. Order today with confidence.","enable_manual_credit_card_capture":false,"store_credit_multiplier":"1.3","buylist_cancel_days":"0","checkout_special_instructions":"","default_exchange_rate":"1","enable_buy_order_notifications":"1","enable_buylist":true,"enable_bcc_buylist_confirmation_emails":false,"enable_tax_on_shipping":true,"enable_sort_by_price":true,"feedback_timespan":"14","home_redirect":"/catalog/magic_singles-core_sets-magic_2012/306","phone":"555-555-5555","state":"WA","enable_referafriend":true,"address":"3400
63
+ NE 110th ST #B-1","payment":"7","contact_name":"Mr. Arux","name":"Arux Gaming
64
+ and Hobbies","display_customer_service_phone":false,"enable_order_notifications":"1","enable_account_approval":false,"enable_watermarking_of_product_photos":false,"watermark_photo":null,"country":"US","contact_email":"donald@crystalcommerce.com","buylist_reminder_days":"0","hide_bank_transfer_details_in_emails":false,"enable_invoice_logo":false}}'
65
+ http_version:
66
+ recorded_at: Thu, 24 Jan 2013 04:47:04 GMT
67
+ recorded_with: VCR 2.2.4
@@ -0,0 +1,7 @@
1
+ require 'spec_helper'
2
+
3
+ describe CrystalApi::Attributes do
4
+ class TestAttributes
5
+ include CrystalApi::Attributes
6
+ end
7
+ end
@@ -0,0 +1,112 @@
1
+ require 'spec_helper'
2
+
3
+ describe CrystalApi::Category do
4
+ describe ".from_json" do
5
+ let(:json_hash) {{
6
+ "category" => {
7
+ "id" => 321,
8
+ "catalog_id" => 1,
9
+ "name" => "Return to Ravnica Block",
10
+ "seoname" => "return_to_ravnica_block",
11
+ "is_root" => false,
12
+ "is_visible_for_buying" => false,
13
+ "is_visible_for_selling" => true,
14
+ "description" => "describe this!",
15
+ "is_leaf" => false,
16
+ "browse_layout" => "Hybrid4x1",
17
+ "photos" => [],
18
+ "buylist_links" => {
19
+ "en" => {
20
+ "href" => "http://www.example.com/buylist/return_to_ravnica_block/321"
21
+ }
22
+ },
23
+ "catalog_links" => {
24
+ "en" => {
25
+ "href" => "http://www.example.com/catalog/return_to_ravnica_block/321"
26
+ }
27
+ },
28
+ "_links" => {
29
+ "self" => { "href" => "/v1/categories/321" },
30
+ "products" => { "href" => "/v1/categories/321/products" },
31
+ "children" => { "href" => "/v1/categories/321/children" },
32
+ "tree" => { "href" => "/v1/categories/321/tree" },
33
+ "parent_category" => { "href" => "/v1/categories/8" }
34
+ },
35
+ "descriptors" => [
36
+ {
37
+ "descriptor" => {
38
+ "is_enable_filter" => true,
39
+ "name" => "Card Type",
40
+ "options" => []
41
+ }
42
+ },
43
+ {
44
+ "descriptor" => {
45
+ "is_enable_filter" => true,
46
+ "name" => "Color",
47
+ "options" => [
48
+ "Artifact",
49
+ "Black",
50
+ "Blue",
51
+ "Green",
52
+ "Land",
53
+ "Multi-Color",
54
+ "Red",
55
+ "White",
56
+ "Colorless"
57
+ ]
58
+ }
59
+ }
60
+ ],
61
+ "_embedded" => {
62
+ "ancestors" => [
63
+ { "category" => { "name" => "My Store" } },
64
+ { "category" => { "name" => "Magic Singles!" } }
65
+ ]
66
+ }
67
+ }
68
+ }}
69
+
70
+ subject { CrystalApi::Category.from_json(json_hash) }
71
+
72
+ its(:id) { should == 321 }
73
+ its(:catalog_id) { should == 1 }
74
+ its(:name) { should == "Return to Ravnica Block" }
75
+ its(:seoname) { should == "return_to_ravnica_block" }
76
+
77
+ its(:is_root) { should == false }
78
+ its(:root?) { should == false }
79
+
80
+ its(:is_leaf) { should == false }
81
+ its(:leaf?) { should == false }
82
+
83
+ its(:is_visible_for_buying) { should == false }
84
+ its(:visible_for_buying?) { should == false }
85
+
86
+ its(:is_visible_for_selling) { should == true }
87
+ its(:visible_for_selling?) { should == true }
88
+
89
+ its(:description) { should == "describe this!" }
90
+ its(:browse_layout) { should == "Hybrid4x1" }
91
+
92
+ its(:catalog_links) { should == {
93
+ "en" => CrystalApi::Url.new(href: "http://www.example.com/catalog/return_to_ravnica_block/321")
94
+ }}
95
+
96
+ its(:buylist_links) { should == {
97
+ "en" => CrystalApi::Url.new(href: "http://www.example.com/buylist/return_to_ravnica_block/321")
98
+ }}
99
+
100
+ its(:descriptors) { should == [
101
+ CrystalApi::Descriptor.new(is_enable_filter: true, name: "Card Type", options: []),
102
+ CrystalApi::Descriptor.new(is_enable_filter: true, name: "Color", options: [
103
+ "Artifact", "Black", "Blue", "Green", "Land", "Multi-Color", "Red",
104
+ "White", "Colorless"])
105
+ ] }
106
+
107
+ its(:ancestors) { should == [
108
+ CrystalApi::Category.new(name: "My Store"),
109
+ CrystalApi::Category.new(name: "Magic Singles!")
110
+ ]}
111
+ end
112
+ end
@@ -0,0 +1,10 @@
1
+ require 'spec_helper'
2
+
3
+ describe CrystalApi::Money do
4
+ describe ".from_json" do
5
+ it "parses the json" do
6
+ CrystalApi::Money.from_json({"money" => {"cents" => 500, "currency" => "USD"}}).
7
+ should == Money.new(500, "USD")
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,31 @@
1
+ require 'spec_helper'
2
+
3
+ describe CrystalApi::PaginatedCollection do
4
+ describe ".from_json" do
5
+ let(:json_hash) {{
6
+ "paginated_collection" => {
7
+ "total_entries" => 33061,
8
+ "total_pages" => 331,
9
+ "previous_page" => nil,
10
+ "_links" => {
11
+ "self" => {
12
+ "href" => "/v1/products"
13
+ },
14
+ "next_page" => {
15
+ "href" => "/v1/products?page=2"
16
+ }
17
+ },
18
+ "next_page" => 2,
19
+ "entries" => [{"product" => {"name" => "Lotus Cobra"}}]
20
+ }
21
+ }}
22
+
23
+ subject { CrystalApi::PaginatedCollection.from_json(json_hash) }
24
+
25
+ its(:total_entries) { should == 33061 }
26
+ its(:total_pages) { should == 331 }
27
+ its(:previous_page) { should == nil }
28
+ its(:next_page) { should == 2}
29
+ its(:entries) { should == [CrystalApi::Product.new(name: "Lotus Cobra")] }
30
+ end
31
+ end