mad_cart 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MzJkMmY4NjNhZmMyZTVhZDQzNmFjMmUyOGUzYWFiN2NmODE0MDBmYQ==
5
- data.tar.gz: !binary |-
6
- YmNmMTgyYWRmNjUyNmM2YmFmYTk1NjBkZDE3MDE1Y2Q0MjY2NDQ3Zg==
2
+ SHA1:
3
+ metadata.gz: 2242589c28d1a7b9945af40b37c0148d5a35369e
4
+ data.tar.gz: 007d24a879edf61f1357bf8ff5f4d80ff53075cf
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- NTkyY2NkMzU2NDM5MWYwYWExOTYyYzdhZjNmYzJkNGVmMzM0YjEyNTQxN2Y5
10
- NmU2NThjYWIwYjY2ZTU4MzIxYzZlZTQxMWRmMmVlMmNiZjg0MmY2ZmY5NjQz
11
- YTU3MDQyZDUxNDk2YmFhNThhNDRlYzc2YjdiY2UxZmNkMWRjOWM=
12
- data.tar.gz: !binary |-
13
- MDlkOTlhZTg5MWEwYTcyYmYyYTczNDZlNmFhYjBmMmE0NDY4YjRhNTI0MjJl
14
- ZGIwNzVhNDczZjgwOTA0MTIzYzlkNjY0NjdlNWIwMmNjZjgyM2NmNTY4Zjky
15
- NDRjN2E2YTEwNzE0MjYwNTRhZmUwZDUwNDdkMjJjNTFhMGExYTk=
6
+ metadata.gz: b1b0050db667f536d5e666164bd477b0cf31920250c3b4ab68f49f626af9072bf7fbd802e242c8b5c13eccb70e9702ac2b6dd453b0873653052c85e56f37cf2a
7
+ data.tar.gz: 3f427925fdcf6e17bb1c7e02decf6efe6b7861b0c23f6d7ec545a5d29cf6e7b75103366e1e79e8a139b214c3505933c1ec8f0527668922f8e21083fba9560180
@@ -25,6 +25,8 @@ module MadCart
25
25
  end
26
26
 
27
27
  def check_required_attributes(args)
28
+ return unless klass.required_attrs
29
+
28
30
  keys = args.keys.map{|a| a.to_s }
29
31
  klass.required_attrs.each do |attr|
30
32
  raise(ArgumentError, "missing argument: #{attr}") if !keys.include?(attr)
@@ -34,7 +36,7 @@ module MadCart
34
36
 
35
37
  def set_attribute(key, value)
36
38
  attr_name = klass.map_attribute_name(key)
37
-
39
+
38
40
  if klass.exposed_attributes.include? attr_name.to_s
39
41
  define_attribute_accessors unless self.respond_to?(attr_name)
40
42
  self.send("#{attr_name}=", value) unless value.nil?
@@ -0,0 +1,7 @@
1
+ module MadCart
2
+ module Model
3
+ class Store
4
+ include MadCart::Model::Base
5
+ end
6
+ end
7
+ end
@@ -82,15 +82,17 @@ module MadCart
82
82
  private :configured_connection_args
83
83
 
84
84
  def ensure_model_format(model, results)
85
- if results.first.is_a?(MadCart::Model::Base)
86
- results
87
- else
85
+ if results.is_a?(Array)
88
86
  map_to_madcart_model(model, results)
87
+ else
88
+ "MadCart::Model::#{model.to_s.classify}".constantize.new(results)
89
89
  end
90
90
  end
91
91
  private :ensure_model_format
92
92
 
93
93
  def map_to_madcart_model(model, results)
94
+ return results if results.first.is_a?(MadCart::Model::Base)
95
+
94
96
  results.map do |args|
95
97
  "MadCart::Model::#{model.to_s.classify}".constantize.new(args)
96
98
  end
@@ -6,6 +6,7 @@ module MadCart
6
6
  create_connection_with :create_connection, :requires => [:api_key, :store_url, :username]
7
7
  fetch :customers, :with => :get_customer_hashes
8
8
  fetch :products, :with => :get_products
9
+ fetch :store, :with => :get_store
9
10
 
10
11
  def valid?
11
12
  check_for_errors do
@@ -74,6 +75,10 @@ module MadCart
74
75
 
75
76
  end
76
77
 
78
+ def get_store
79
+ parse_response { connection.get('store.json') }
80
+ end
81
+
77
82
  def parse_response(&block)
78
83
  response = check_for_errors &block
79
84
  return [] if empty_body?(response)
@@ -1,3 +1,3 @@
1
1
  module MadCart
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
data/lib/mad_cart.rb CHANGED
@@ -16,6 +16,7 @@ require 'mad_cart/inheritable_attributes'
16
16
  require 'mad_cart/model/base'
17
17
  require 'mad_cart/model/customer'
18
18
  require 'mad_cart/model/product'
19
+ require 'mad_cart/model/store'
19
20
 
20
21
  # stores
21
22
  require 'mad_cart/store/base'
@@ -0,0 +1,84 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://support%40madmimi.com:0ff0e3939f5f160f36047cf0caa6f699fe24bdeb@store-cr4wsh4.mybigcommerce.com/api/v2/customers.json?min_id=1
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Thu, 21 Aug 2014 21:21:17 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Last-Modified:
32
+ - Fri, 26 Apr 2013 12:16:30 +0000
33
+ X-Bc-Apilimit-Remaining:
34
+ - '19964'
35
+ X-Bc-Store-Version:
36
+ - 7.6.0
37
+ body:
38
+ encoding: UTF-8
39
+ string: '[{"id":1,"company":"CompanyNAME","first_name":"First","last_name":"Customer","email":"this@email.com","phone":"","date_created":"Fri,
40
+ 26 Apr 2013 09:18:26 +0000","date_modified":"Fri, 26 Apr 2013 12:16:30 +0000","store_credit":"1000.0000","registration_ip_address":"196.209.229.215","customer_group_id":0,"notes":"","addresses":{"url":"https:\/\/store-cr4wsh4.mybigcommerce.com\/api\/v2\/customers\/1\/addresses.json","resource":"\/customers\/1\/addresses"}}]'
41
+ http_version:
42
+ recorded_at: Thu, 21 Aug 2014 21:21:17 GMT
43
+ - request:
44
+ method: get
45
+ uri: https://support%40madmimi.com:0ff0e3939f5f160f36047cf0caa6f699fe24bdeb@store-cr4wsh4.mybigcommerce.com/api/v2/customers.json?min_id=1
46
+ body:
47
+ encoding: UTF-8
48
+ string: '[{"id":1,"company":"CompanyNAME","first_name":"First","last_name":"Customer","email":"this@email.com","phone":"","date_created":"Fri,
49
+ 26 Apr 2013 09:18:26 +0000","date_modified":"Fri, 26 Apr 2013 12:16:30 +0000","store_credit":"1000.0000","registration_ip_address":"196.209.229.215","customer_group_id":0,"notes":"","addresses":{"url":"https:\/\/store-cr4wsh4.mybigcommerce.com\/api\/v2\/customers\/1\/addresses.json","resource":"\/customers\/1\/addresses"}}]'
50
+ headers:
51
+ User-Agent:
52
+ - Faraday v0.9.0
53
+ Accept-Encoding:
54
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
55
+ Accept:
56
+ - "*/*"
57
+ response:
58
+ status:
59
+ code: 200
60
+ message: OK
61
+ headers:
62
+ Server:
63
+ - nginx
64
+ Date:
65
+ - Thu, 21 Aug 2014 21:21:18 GMT
66
+ Content-Type:
67
+ - application/json
68
+ Transfer-Encoding:
69
+ - chunked
70
+ Connection:
71
+ - keep-alive
72
+ Last-Modified:
73
+ - Fri, 26 Apr 2013 12:16:30 +0000
74
+ X-Bc-Apilimit-Remaining:
75
+ - '19963'
76
+ X-Bc-Store-Version:
77
+ - 7.6.0
78
+ body:
79
+ encoding: UTF-8
80
+ string: '[{"id":1,"company":"CompanyNAME","first_name":"First","last_name":"Customer","email":"this@email.com","phone":"","date_created":"Fri,
81
+ 26 Apr 2013 09:18:26 +0000","date_modified":"Fri, 26 Apr 2013 12:16:30 +0000","store_credit":"1000.0000","registration_ip_address":"196.209.229.215","customer_group_id":0,"notes":"","addresses":{"url":"https:\/\/store-cr4wsh4.mybigcommerce.com\/api\/v2\/customers\/1\/addresses.json","resource":"\/customers\/1\/addresses"}}]'
82
+ http_version:
83
+ recorded_at: Thu, 21 Aug 2014 21:21:18 GMT
84
+ recorded_with: VCR 2.5.0
@@ -0,0 +1,77 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://support%40madmimi.com:an-invalid-key@store-cr4wsh4.mybigcommerce.com/api/v2/time.json
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - "*/*"
16
+ response:
17
+ status:
18
+ code: 401
19
+ message: Unauthorized
20
+ headers:
21
+ Server:
22
+ - nginx
23
+ Date:
24
+ - Thu, 21 Aug 2014 21:37:06 GMT
25
+ Content-Type:
26
+ - application/json
27
+ Transfer-Encoding:
28
+ - chunked
29
+ Connection:
30
+ - keep-alive
31
+ Www-Authenticate:
32
+ - Basic
33
+ X-Bc-Store-Version:
34
+ - 7.6.0
35
+ body:
36
+ encoding: UTF-8
37
+ string: '[{"status":401,"message":"The specified credentials were invalid."}]'
38
+ http_version:
39
+ recorded_at: Thu, 21 Aug 2014 21:37:06 GMT
40
+ - request:
41
+ method: get
42
+ uri: https://support%40madmimi.com:an-invalid-key@store-cr4wsh4.mybigcommerce.com/api/v2/time.json
43
+ body:
44
+ encoding: UTF-8
45
+ string: '[{"status":401,"message":"The specified credentials were invalid."}]'
46
+ headers:
47
+ User-Agent:
48
+ - Faraday v0.9.0
49
+ Accept-Encoding:
50
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
51
+ Accept:
52
+ - "*/*"
53
+ response:
54
+ status:
55
+ code: 401
56
+ message: Unauthorized
57
+ headers:
58
+ Server:
59
+ - nginx
60
+ Date:
61
+ - Thu, 21 Aug 2014 21:37:07 GMT
62
+ Content-Type:
63
+ - application/json
64
+ Transfer-Encoding:
65
+ - chunked
66
+ Connection:
67
+ - keep-alive
68
+ Www-Authenticate:
69
+ - Basic
70
+ X-Bc-Store-Version:
71
+ - 7.6.0
72
+ body:
73
+ encoding: UTF-8
74
+ string: '[{"status":401,"message":"The specified credentials were invalid."}]'
75
+ http_version:
76
+ recorded_at: Thu, 21 Aug 2014 21:37:08 GMT
77
+ recorded_with: VCR 2.5.0
@@ -2,7 +2,7 @@
2
2
  http_interactions:
3
3
  - request:
4
4
  method: get
5
- uri: https://admin:0ff0e3939f5f160f36047cf0caa6f699fe24bdeb@store-cr4wsh4.mybigcommerce.com/api/v2/products.json
5
+ uri: https://support%40madmimi.com:0ff0e3939f5f160f36047cf0caa6f699fe24bdeb@store-cr4wsh4.mybigcommerce.com/api/v2/products.json
6
6
  body:
7
7
  encoding: US-ASCII
8
8
  string: ''
@@ -58,7 +58,7 @@ http_interactions:
58
58
  recorded_at: Tue, 09 Jul 2013 09:35:32 GMT
59
59
  - request:
60
60
  method: get
61
- uri: https://admin:0ff0e3939f5f160f36047cf0caa6f699fe24bdeb@store-cr4wsh4.mybigcommerce.com/api/v2/products.json
61
+ uri: https://support%40madmimi.com:0ff0e3939f5f160f36047cf0caa6f699fe24bdeb@store-cr4wsh4.mybigcommerce.com/api/v2/products.json
62
62
  body:
63
63
  encoding: US-ASCII
64
64
  string: ! '[]'
@@ -95,7 +95,7 @@ http_interactions:
95
95
  recorded_at: Thu, 01 Aug 2013 13:06:03 GMT
96
96
  - request:
97
97
  method: get
98
- uri: https://admin:0ff0e3939f5f160f36047cf0caa6f699fe24bdeb@store-cr4wsh4.mybigcommerce.com/api/v2/customers.json?min_id=1
98
+ uri: https://support%40madmimi.com:0ff0e3939f5f160f36047cf0caa6f699fe24bdeb@store-cr4wsh4.mybigcommerce.com/api/v2/customers.json?min_id=1
99
99
  body:
100
100
  encoding: US-ASCII
101
101
  string: ! '[{"id":1,"company":"CompanyNAME","first_name":"First","last_name":"Customer","email":"this@email.com","phone":"","date_created":"Fri,
@@ -133,7 +133,7 @@ http_interactions:
133
133
  recorded_at: Thu, 01 Aug 2013 14:27:03 GMT
134
134
  - request:
135
135
  method: get
136
- uri: https://admin:0ff0e3939f5f160f36047cf0caa6f699fe24bdeb@store-cr4wsh4.mybigcommerce.com/api/v2/customers.json?min_id=1
136
+ uri: https://support%40madmimi.com:0ff0e3939f5f160f36047cf0caa6f699fe24bdeb@store-cr4wsh4.mybigcommerce.com/api/v2/customers.json?min_id=1
137
137
  body:
138
138
  encoding: US-ASCII
139
139
  string: ! '[]'