retentiongrid 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/retentiongrid/api.rb +19 -8
- data/lib/retentiongrid/customer.rb +5 -4
- data/lib/retentiongrid/errors.rb +3 -0
- data/lib/retentiongrid/order.rb +6 -4
- data/lib/retentiongrid/version.rb +1 -1
- data/retentiongrid.gemspec +1 -1
- data/spec/integration/customer_spec.rb +12 -11
- data/spec/integration/order_spec.rb +11 -10
- 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: 5d20df15a78c63d358f0b952f55c8263f70c196f
|
4
|
+
data.tar.gz: cb70219f52897bdca4f4a820b2aca9ed62359921
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58bdd1a1a3bb3429cd815e8a24b5f1db78c454c54881215335a6932107dd79091657c9bb1511edef0fec8485e2535c273c15032d110db6c7d2bea5c9e0cb9f56
|
7
|
+
data.tar.gz: 4f39e1f466d9905c4961e9c06044118cfee6521417abf6714f94de94167a3210850b7292512bde88e9aeaf1b476de2a27f948f27a03a71be29cd047249e8951d
|
data/lib/retentiongrid/api.rb
CHANGED
@@ -12,16 +12,26 @@ module Retentiongrid
|
|
12
12
|
include HTTParty
|
13
13
|
|
14
14
|
base_uri 'https://app.retentiongrid.com/api'
|
15
|
+
headers 'Accept' => 'application/json'
|
15
16
|
logger ::Logger.new("log/httparty.log"), :debug, :curl
|
16
17
|
|
17
|
-
def self.api_key=(api_key)
|
18
|
-
default_params token: api_key
|
19
|
-
end
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
19
|
+
class << self
|
20
|
+
|
21
|
+
def api_key=(api_key)
|
22
|
+
default_params token: api_key
|
23
|
+
end
|
24
|
+
|
25
|
+
def get_with_response_check(path, options={}, &block)
|
26
|
+
check_response_codes(get_without_response_check(path, options={}, &block))
|
27
|
+
end
|
28
|
+
alias_method_chain :get, :response_check
|
29
|
+
|
30
|
+
def post_with_response_check(path, options={}, &block)
|
31
|
+
check_response_codes(post_without_response_check(path, options={}, &block))
|
32
|
+
end
|
33
|
+
alias_method_chain :post, :response_check
|
34
|
+
|
25
35
|
end
|
26
36
|
|
27
37
|
private
|
@@ -29,13 +39,14 @@ module Retentiongrid
|
|
29
39
|
def self.check_response_codes(response)
|
30
40
|
body = response.body
|
31
41
|
case response.code.to_i
|
32
|
-
when 200 then return
|
42
|
+
when 200 then return response
|
33
43
|
when 400 then raise BadRequest.new(body)
|
34
44
|
when 401 then raise Unauthorized.new(body)
|
35
45
|
when 403 then raise Forbidden.new(body)
|
36
46
|
when 404 then raise NotFound.new(body)
|
37
47
|
when 405 then raise MethodNotAllowed.new(body)
|
38
48
|
when 410 then raise Gone.new(body)
|
49
|
+
when 422 then raise UnprocessableEntity.new(body)
|
39
50
|
when 500 then raise ServerError, 'Internal Server Error'
|
40
51
|
when 503 then raise Unavailable, 'Service Unavailable'
|
41
52
|
else raise "Unknown response code: #{response.code}"
|
@@ -26,7 +26,7 @@ module Retentiongrid
|
|
26
26
|
def self.find(customer_id)
|
27
27
|
begin
|
28
28
|
result = Api.get("/customers/#{customer_id}")
|
29
|
-
new(result.parsed_response)
|
29
|
+
new(result.parsed_response["rg_customer"])
|
30
30
|
rescue NotFound
|
31
31
|
nil
|
32
32
|
end
|
@@ -35,8 +35,8 @@ module Retentiongrid
|
|
35
35
|
|
36
36
|
|
37
37
|
def save
|
38
|
-
result = Api.post("/customers/#{customer_id}", attributes)
|
39
|
-
Customer.new(result.parsed_response)
|
38
|
+
result = Api.post("/customers/#{customer_id}", body: attributes.to_json)
|
39
|
+
Customer.new(result.parsed_response["rg_customer"])
|
40
40
|
end
|
41
41
|
|
42
42
|
def save!
|
@@ -49,7 +49,8 @@ module Retentiongrid
|
|
49
49
|
|
50
50
|
def attributes
|
51
51
|
ATTRIBUTES_NAMES.inject({}) do |attribs, attrib_name|
|
52
|
-
|
52
|
+
value = self.send(attrib_name)
|
53
|
+
attribs[attrib_name] = value unless value.nil?
|
53
54
|
attribs
|
54
55
|
end
|
55
56
|
end
|
data/lib/retentiongrid/errors.rb
CHANGED
@@ -27,6 +27,9 @@ module Retentiongrid
|
|
27
27
|
# that the object existed at some point, but was deleted.
|
28
28
|
class Gone < HTTParty::Error; end # 410
|
29
29
|
|
30
|
+
# The request was well-formed but was unable to be followed due to semantic errors.
|
31
|
+
class UnprocessableEntity < HTTParty::Error; end # 422
|
32
|
+
|
30
33
|
# Unspecified API server error.
|
31
34
|
class ServerError < HTTParty::Error; end # 500
|
32
35
|
|
data/lib/retentiongrid/order.rb
CHANGED
@@ -45,15 +45,16 @@ module Retentiongrid
|
|
45
45
|
def self.find(order_id)
|
46
46
|
begin
|
47
47
|
result = Api.get("/orders/#{order_id}")
|
48
|
-
new(result.parsed_response)
|
48
|
+
new(result.parsed_response["rg_order"])
|
49
49
|
rescue NotFound
|
50
50
|
nil
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
54
|
def save
|
55
|
-
result = Api.post("/orders/#{order_id}", attributes)
|
56
|
-
|
55
|
+
result = Api.post("/orders/#{order_id}", { body: attributes.to_json })
|
56
|
+
puts result.inspect
|
57
|
+
Order.new(result.parsed_response["rg_order"])
|
57
58
|
end
|
58
59
|
|
59
60
|
def destroy
|
@@ -62,7 +63,8 @@ module Retentiongrid
|
|
62
63
|
|
63
64
|
def attributes
|
64
65
|
ATTRIBUTES_NAMES.inject({}) do |attribs, attrib_name|
|
65
|
-
|
66
|
+
value = self.send(attrib_name)
|
67
|
+
attribs[attrib_name] = value unless value.nil?
|
66
68
|
attribs
|
67
69
|
end
|
68
70
|
end
|
data/retentiongrid.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Christoph Bünte"]
|
10
10
|
spec.email = ["info@christophbuente.de"]
|
11
11
|
spec.summary = "A ruby client for retentiongrid.com API."
|
12
|
-
spec.homepage = ""
|
12
|
+
spec.homepage = "https://github.com/christoph-buente/retentiongrid"
|
13
13
|
spec.license = "MIT"
|
14
14
|
|
15
15
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -8,17 +8,18 @@ RSpec.describe Customer do
|
|
8
8
|
|
9
9
|
def valid_customer
|
10
10
|
<<-EOF
|
11
|
-
{
|
12
|
-
"customer_id": "C123",
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
11
|
+
{ "rg_customer":
|
12
|
+
{ "customer_id": "C123",
|
13
|
+
"first_name": "John",
|
14
|
+
"full_name": "John Smith",
|
15
|
+
"email": "john.smith@example.com",
|
16
|
+
"country": "DE",
|
17
|
+
"city": "Berlin",
|
18
|
+
"state": "Berlin",
|
19
|
+
"postal_code": "10437",
|
20
|
+
"tags": "wholesale",
|
21
|
+
"accepts_email_marketing": "true"
|
22
|
+
}
|
22
23
|
}
|
23
24
|
EOF
|
24
25
|
end
|
@@ -8,16 +8,17 @@ RSpec.describe Order do
|
|
8
8
|
|
9
9
|
def valid_order
|
10
10
|
<<-EOF
|
11
|
-
{
|
12
|
-
"order_id": "A123",
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
11
|
+
{ "rg_order":
|
12
|
+
{ "order_id": "A123",
|
13
|
+
"customer_id": "C123",
|
14
|
+
"status": "ok",
|
15
|
+
"total_price": 12.00,
|
16
|
+
"total_discounts": 1.00,
|
17
|
+
"currency": "EUR",
|
18
|
+
"canceled_shipped": false,
|
19
|
+
"canceled_shop_fault": false,
|
20
|
+
"order_created_at": "2014-03-12 13:35:10"
|
21
|
+
}
|
21
22
|
}
|
22
23
|
EOF
|
23
24
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: retentiongrid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christoph Bünte
|
@@ -165,7 +165,7 @@ files:
|
|
165
165
|
- spec/models/customer_spec.rb
|
166
166
|
- spec/models/order_spec.rb
|
167
167
|
- spec/spec_helper.rb
|
168
|
-
homepage:
|
168
|
+
homepage: https://github.com/christoph-buente/retentiongrid
|
169
169
|
licenses:
|
170
170
|
- MIT
|
171
171
|
metadata: {}
|