get_response_api 0.1.0 → 0.2.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 53f8f5f8f635d7b3a91092e45abdb530a36fff44
4
- data.tar.gz: 8ed6db53652f807d2ea5977dc6bf50571e77dba9
3
+ metadata.gz: aa37f0f5319a44641fc9753cd64a11d78a644a8b
4
+ data.tar.gz: 44364fa431a21a1e440484551b3563e437e6a651
5
5
  SHA512:
6
- metadata.gz: 387795dc3604785cde2ef0150424eb9b2e2562b68bc578058b2ed3d17b96943f0d5c714e0f7f905eed9d9537b2ee23fa19867a05a1b73f446a6cc40017efc1a6
7
- data.tar.gz: 72d94f2f591fc13214f9b369749037cc7f68efe8b55f70e3cf8a260859347c29dc3163691cb0408df4828c2aa97a670b96a320ce12cbfa648190016ca8fbcca9
6
+ metadata.gz: 88e2c3d7a0f44a0cdfa8688ef9eccd540941049bfeb3e0214e4d1c895098188da713348e65891ba9046eebc3af57b9c2289770db4381c2553329b3584aa9f096
7
+ data.tar.gz: 8ac94955e7bcf569978c4288265a7c130e2633e9325dd5fa91c3807d2e33fa3547d8a2939377613ffa8ea010ea4bb5e03da9326ec23952e43d76bb73fc032284
@@ -5,18 +5,11 @@ module GetResponseApi
5
5
  end
6
6
 
7
7
  def account
8
- response = @connection.get('/accounts').parsed_response
9
-
10
- if error?(response) && response['message']
11
- return response['message']
12
- end
13
- response
8
+ @connection.request(:get, '/accounts')
14
9
  end
15
10
 
16
- private
17
-
18
- def error?(response)
19
- response['httpStatus']
11
+ def campaigns
12
+ @connection.request(:get, '/campaigns')
20
13
  end
21
14
  end
22
15
  end
@@ -2,26 +2,28 @@ require 'httparty'
2
2
 
3
3
  module GetResponseApi
4
4
  class Connection
5
- API_ENDPOINT = 'https://api.getresponse.com/v3'
5
+ API_ENDPOINT = 'https://api.getresponse.com/v3'.freeze
6
6
  TIMEOUT = 7
7
7
 
8
8
  def initialize(api_key)
9
9
  @api_key = api_key
10
10
  end
11
11
 
12
- def post(path, body: {}, headers: {})
13
- headers.merge!(auth)
14
- HTTParty.post(
15
- "#{API_ENDPOINT}#{path}",
16
- body: body.to_json,
17
- headers: headers,
18
- timeout: TIMEOUT
19
- )
12
+ def request(method, path)
13
+ response = http_request(method, path).parsed_response
14
+
15
+ if error?(response) && response['message']
16
+ return response['message']
17
+ end
18
+ response
20
19
  end
21
20
 
22
- def get(path, body: {}, headers: {})
21
+ private
22
+
23
+ def http_request(request, path, body: {}, headers: {})
23
24
  headers.merge!(auth)
24
- HTTParty.get(
25
+ HTTParty.public_send(
26
+ request,
25
27
  "#{API_ENDPOINT}#{path}",
26
28
  body: body.to_json,
27
29
  headers: headers,
@@ -29,13 +31,15 @@ module GetResponseApi
29
31
  )
30
32
  end
31
33
 
32
- private
33
-
34
34
  def auth
35
35
  {
36
36
  'X-Auth-Token' => "api-key #{@api_key}",
37
37
  'Content-Type' => 'application/json'
38
38
  }
39
39
  end
40
+
41
+ def error?(response)
42
+ response.is_a?(Hash) && response['httpStatus']
43
+ end
40
44
  end
41
45
  end
@@ -1,3 +1,3 @@
1
1
  module GetResponseApi
2
- VERSION = '0.1.0'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: get_response_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Juliane Lima
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-08-31 00:00:00.000000000 Z
12
+ date: 2017-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler