balihoo_lpc_client 0.5.2 → 0.6.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: a419f5a1be223fef3953c4d503c46ca1efc38f7e
4
- data.tar.gz: 0b8cdec43c0f6c5548824557760e3d4f0b212c54
3
+ metadata.gz: 591af8860b95e6f9fba8075f1a24049457aa1e74
4
+ data.tar.gz: 6b933abb027d4439683b06fc7239844bcf3fc265
5
5
  SHA512:
6
- metadata.gz: 645048672a5b8baa72902b266866787ffe6db5822b478680d3563af2b924fb235426dac7f7bf3933ada5a5df7d36ad9130b6f3f1fcd1cdc1a791b518cd44d8e2
7
- data.tar.gz: de75e508e3f92fd324d9625f16552aee8c73de5b92a3cf5dc98ccd2f78d7293957a6accc3e71d9db91d0e73bc833fe72cc662c33a06ad41cfda2e554824d34b3
6
+ metadata.gz: f934bee38ddb572e0dc06d012a56d0313bfbc0f9b52dd0c8f32dbd9ab01bdd0852173cf80fd28451cb94a4e35bf57bb358f14f69f0ad71da25b2c1a738f986c4
7
+ data.tar.gz: 722fccbfed104e79bcf88459dde8f0d6f56bba88dd993362d007217bcc31385c94556a49eab522cfeb672b38dc791b1919547107b0cc467db3af28c0ed6aea31
@@ -2,9 +2,9 @@ module BalihooLpcClient
2
2
  module Request
3
3
  class Authentication < Base
4
4
  def authenticate!
5
- response = self.class.post('/genClientAPIKey', opts)
5
+ response = self.class.post('/genClientAPIKey', opts).parsed_response
6
6
  handle_errors_with(klass: AuthenticationError, response: response)
7
- handle_success(response.parsed_response)
7
+ handle_success(response: response)
8
8
  end
9
9
 
10
10
  private
@@ -21,8 +21,8 @@ module BalihooLpcClient
21
21
  }
22
22
  end
23
23
 
24
- def handle_success(data)
25
- auth = Response::Authentication.new(data)
24
+ def handle_success(response:)
25
+ auth = Response::Authentication.new(response)
26
26
  config.client_id = auth.client_id
27
27
  config.client_api_key = auth.client_api_key
28
28
  auth
@@ -17,8 +17,12 @@ module BalihooLpcClient
17
17
  end
18
18
 
19
19
  def handle_errors_with(klass:, response:)
20
- unless response.parsed_response.is_a?(Hash)
21
- raise klass, response.parsed_response
20
+ if response.is_a?(String)
21
+ if response =~ /session has expired/
22
+ raise ApiSessionExpiredError, response
23
+ else
24
+ raise klass, response
25
+ end
22
26
  end
23
27
  end
24
28
  end
@@ -3,6 +3,7 @@ module BalihooLpcClient
3
3
  class Campaigns < ApiBase
4
4
  def fetch
5
5
  response = self.class.get('/campaigns', opts).parsed_response
6
+ handle_errors_with(klass: ApiResponseError, response: response)
6
7
  handle_response(response: response, klass: Response::Campaign)
7
8
  end
8
9
  end
@@ -3,6 +3,7 @@ module BalihooLpcClient
3
3
  class CampaignsWithTactics < ApiBase
4
4
  def fetch
5
5
  response = self.class.get('/campaignswithtactics', opts).parsed_response
6
+ handle_errors_with(klass: ApiResponseError, response: response)
6
7
  handle_response(response: response, klass: Response::Campaign)
7
8
  end
8
9
  end
@@ -10,6 +10,7 @@ module BalihooLpcClient
10
10
 
11
11
  def fetch
12
12
  response = self.class.get("/tactic/#{tactic_id}/metrics", opts).parsed_response
13
+ handle_errors_with(klass: ApiResponseError, response: response)
13
14
  handle_response(response: response, klass: Response::Metric, mappable: false)
14
15
  end
15
16
  end
@@ -10,11 +10,17 @@ module BalihooLpcClient
10
10
 
11
11
  def fetch
12
12
  response = self.class.get("/campaign/#{campaign_id}/tactics", opts).parsed_response
13
+ handle_errors_with(klass: ApiResponseError, response: response)
14
+ handle_response(response: response, klass: Response::Tactic)
15
+ end
16
+
17
+ private
13
18
 
19
+ def handle_response(response:, klass:, mappable: true)
14
20
  if multiple_locations?
15
- multiple_locations(response: response, klass: Response::Tactic, mappable: true)
21
+ multiple_locations(response: response, klass: klass, mappable: mappable)
16
22
  else
17
- single_location(response: response['tactics'], klass: Response::Tactic, mappable: true)
23
+ single_location(response: response['tactics'], klass: klass, mappable: mappable)
18
24
  end
19
25
  end
20
26
  end
@@ -3,6 +3,7 @@ module BalihooLpcClient
3
3
  class WebsiteMetrics < ApiBase
4
4
  def fetch
5
5
  response = self.class.get("/websitemetrics", opts).parsed_response
6
+ handle_errors_with(klass: ApiResponseError, response: response)
6
7
  handle_response(response: response, klass: Response::WebsiteMetric, mappable: false)
7
8
  end
8
9
  end
@@ -1,3 +1,3 @@
1
1
  module BalihooLpcClient
2
- VERSION = "0.5.2"
2
+ VERSION = "0.6.0"
3
3
  end
@@ -25,4 +25,6 @@ module BalihooLpcClient
25
25
  class AuthenticationError < BalihooLpcError; end
26
26
  class ApiOptionError < BalihooLpcError; end
27
27
  class NotAuthenticatedError < BalihooLpcError; end
28
+ class ApiSessionExpiredError < BalihooLpcError; end
29
+ class ApiResponseError < BalihooLpcError; end
28
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: balihoo_lpc_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - JD Guzman