bigcommerce_api 0.5.0 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bigcommerce_api/base.rb +8 -0
- data/lib/bigcommerce_api/resource.rb +19 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 411e4129bc649ca6cb74c1f10a31fea7574ed58c
|
4
|
+
data.tar.gz: 8ed961c57ea570e952b0779c927d732d52bfd27b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 37ed1fe0e7ae5b30794d699ca00f131c2f7e629dbf06aff0a41bea461cd40b028260e980f16f7ea9044a942e52e9a32a3bc139264115cb5780d83e0240dd3e1d
|
7
|
+
data.tar.gz: 95dc2de86f72029eb7fb42b6eca47e2792cf8c8bf774305f66f12e485e283ff27823c58fa507a98d20b622504a31caf7ade729067a56baf5a9bded0253c3a03a
|
data/lib/bigcommerce_api/base.rb
CHANGED
@@ -51,9 +51,17 @@ module BigcommerceAPI
|
|
51
51
|
def attributes(strip_empty=false)
|
52
52
|
hash = {}
|
53
53
|
self.instance_variables.each {|var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) if (var.to_s['_hash'].nil? and var.to_s['_resource'].nil? and var.to_s[self.resource + '_type'].nil?) }
|
54
|
+
# Strip out our extra attributes
|
55
|
+
hash.delete('errors')
|
56
|
+
hash.delete('attributes_were')
|
57
|
+
|
58
|
+
# Clean up the date
|
54
59
|
hash = BigcommerceAPI::Resource.date_adjust(hash)
|
60
|
+
|
61
|
+
# Strip empty fields
|
55
62
|
BigcommerceAPI::Resource.clean!(hash) if strip_empty
|
56
63
|
hash.delete('id') if strip_empty
|
64
|
+
|
57
65
|
return hash
|
58
66
|
end
|
59
67
|
|
@@ -15,6 +15,7 @@ module BigcommerceAPI
|
|
15
15
|
k = "#{self.resource}_#{k}" if k == 'type'
|
16
16
|
send(:"#{k}=", val) if self.respond_to? "#{k}="
|
17
17
|
end
|
18
|
+
self.attributes_were = data
|
18
19
|
end
|
19
20
|
|
20
21
|
def save
|
@@ -25,7 +26,11 @@ module BigcommerceAPI
|
|
25
26
|
if self.id.nil?
|
26
27
|
response = BigcommerceAPI::Base.post("/#{url}", :body => self.attributes(true).to_json)
|
27
28
|
else
|
28
|
-
|
29
|
+
# only send updated attributes
|
30
|
+
attrs = self.attributes
|
31
|
+
body = Hash.new
|
32
|
+
self.changed.each{|c| body[c] = attrs[c]}
|
33
|
+
response = BigcommerceAPI::Base.put("/#{url}/#{self.id}", :body => body.to_json)
|
29
34
|
end
|
30
35
|
if response.success?
|
31
36
|
return self.id.nil? ? self.class.new(response.parsed_response) : true
|
@@ -61,6 +66,15 @@ module BigcommerceAPI
|
|
61
66
|
nil
|
62
67
|
end
|
63
68
|
|
69
|
+
def changed
|
70
|
+
changed = Array.new
|
71
|
+
self.attributes.each do |k, v|
|
72
|
+
changed << k if v != attributes_were[k]
|
73
|
+
end
|
74
|
+
changed -= %w[attributes_were errors]
|
75
|
+
return changed
|
76
|
+
end
|
77
|
+
|
64
78
|
class << self
|
65
79
|
attr_accessor :has_many_options, :has_one_options, :belongs_to_options
|
66
80
|
|
@@ -147,7 +161,10 @@ module BigcommerceAPI
|
|
147
161
|
r = BigcommerceAPI::Base.get("/#{resource}/#{id}")
|
148
162
|
(r.success? and !r.nil?) ? self.new(r) : nil
|
149
163
|
end
|
150
|
-
end
|
164
|
+
end # end class methods
|
165
|
+
|
166
|
+
private
|
167
|
+
attr_accessor :attributes_were
|
151
168
|
|
152
169
|
end
|
153
170
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bigcommerce_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Dickson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|