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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c1c260a3fac75b7eb9554b20a70288a5151d07e5
4
- data.tar.gz: ed4661a6a5484c03722effc016a0c54c577bda7f
3
+ metadata.gz: 5d20df15a78c63d358f0b952f55c8263f70c196f
4
+ data.tar.gz: cb70219f52897bdca4f4a820b2aca9ed62359921
5
5
  SHA512:
6
- metadata.gz: 813d5e58d046ec945e7992bbffbe9a3935143f39af01c46eec8a8e9f0f7fb1e60c03fdb18b21f164086593f9dc1d7c653039cca992373e17779e66f01308ccb4
7
- data.tar.gz: 25d7b57cb53bdaac461cd13d80d65480af98299de786f87c411537edc5f4bf7217032f0da27d6301b9a5e0b3f341555f9f9e7df743c9a9024892371d1d21c683
6
+ metadata.gz: 58bdd1a1a3bb3429cd815e8a24b5f1db78c454c54881215335a6932107dd79091657c9bb1511edef0fec8485e2535c273c15032d110db6c7d2bea5c9e0cb9f56
7
+ data.tar.gz: 4f39e1f466d9905c4961e9c06044118cfee6521417abf6714f94de94167a3210850b7292512bde88e9aeaf1b476de2a27f948f27a03a71be29cd047249e8951d
@@ -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
- def self.get(path, options={}, &block)
22
- response = super(path, options={}, &block)
23
- check_response_codes(response)
24
- response
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
- attribs[attrib_name] = self.send(attrib_name)
52
+ value = self.send(attrib_name)
53
+ attribs[attrib_name] = value unless value.nil?
53
54
  attribs
54
55
  end
55
56
  end
@@ -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
 
@@ -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
- Order.new(result.parsed_response)
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
- attribs[attrib_name] = self.send(attrib_name)
66
+ value = self.send(attrib_name)
67
+ attribs[attrib_name] = value unless value.nil?
66
68
  attribs
67
69
  end
68
70
  end
@@ -1,3 +1,3 @@
1
1
  module Retentiongrid
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
- "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"
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
- "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"
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.1
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: {}