action_kit_rest 0.4.6 → 0.4.7

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
  SHA256:
3
- metadata.gz: 2116d0818685f8278921f966f7f4dfb53d4121c983642bb431a13267de077195
4
- data.tar.gz: 19e5351054a60071bef7926ea245ad4f1392a7aa33e929ef44fbb590f18335d1
3
+ metadata.gz: 1817fcc57f6d22b7c399e0face9405049f77417e6ea2b27c9e32218be76af124
4
+ data.tar.gz: 0eb382953e3c3c691191ce9f9c0ff61f5d39cefac40e77921ba2bc4d5366068f
5
5
  SHA512:
6
- metadata.gz: 61722ea2d57c2da9e942351d1651ddfc8b3c2d8df337736aab9d9ce57d4f28993ac8be1f83f6e2f5b88a6f463e21849d5df353ac3d155791be8e57ce4ce2884d
7
- data.tar.gz: efa307aa27a974fa7a93eba9ebf3ebacc6e6b4ba7a11abc63cbaed748c27d5346477dfa19cc8d01d93e4e3986363fed50de7b110f4d02b621e9301e0f14229e9
6
+ metadata.gz: f07602cc5779ae7eb6c7cfd5bad09ec780443c8b0e702a36264035a92add5b4ca06135196e4ea41aa6dcfa0e2d8ea7effa4777adc57e0842666199989db9bd39
7
+ data.tar.gz: cd5c4e3b3e70f5979cd42981b9c116ef475cf9af06ebd8e8c857b594d7a43f15dc9e12fec86de117adda5b691cc0b52571c461ef46035bee8ab97b09742e76ee
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Juwelier::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: action_kit_rest 0.4.6 ruby lib
5
+ # stub: action_kit_rest 0.4.7 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "action_kit_rest".freeze
9
- s.version = "0.4.6"
9
+ s.version = "0.4.7"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["Nathan Woodhull".freeze, "Diego Marcet".freeze, "Grey Moore".freeze]
14
- s.date = "2021-09-29"
14
+ s.date = "2021-10-05"
15
15
  s.description = "Gem for interacting with the ActionKit API".freeze
16
16
  s.email = "systems@controlshiftlabs.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -77,6 +77,7 @@ Gem::Specification.new do |s|
77
77
  "spec/lib/action_kit_rest/actions/event_create_action_spec.rb",
78
78
  "spec/lib/action_kit_rest/actions/event_signup_action_spec.rb",
79
79
  "spec/lib/action_kit_rest/allowed_user_field_spec.rb",
80
+ "spec/lib/action_kit_rest/api_spec.rb",
80
81
  "spec/lib/action_kit_rest/logger_spec.rb",
81
82
  "spec/lib/action_kit_rest/page_spec.rb",
82
83
  "spec/lib/action_kit_rest/pages/event_campaign_page_spec.rb",
@@ -8,7 +8,7 @@ module ActionKitRest
8
8
  if (400...600).include? status_code
9
9
  if status_code == 400
10
10
  response_body = response[:body]
11
- if JSON.parse(response_body)['errors'] == { 'mailing_id' => ['Unable to associate this mailing ID with account.'] }
11
+ if ActionKitRest::Response::InvalidAkidError.matches?(JSON.parse(response_body)['errors'])
12
12
  raise ActionKitRest::Response::InvalidAkidError.new(url: response[:url].to_s, body: response_body)
13
13
  else
14
14
  raise ActionKitRest::Response::ValidationError.new(url: response[:url].to_s, body: response_body)
@@ -7,7 +7,7 @@ module ActionKitRest
7
7
 
8
8
  def initialize(params)
9
9
  self.url = params[:url]
10
- self.body = params[:body]
10
+ self.body = params[:body].dup
11
11
  self.errors = JSON.parse(params[:body])['errors']
12
12
  super()
13
13
  end
@@ -23,6 +23,17 @@ module ActionKitRest
23
23
  end
24
24
 
25
25
  class InvalidAkidError < ValidationError
26
+ MATCHING_ERRORS = ['Unable to associate this mailing ID with account.',
27
+ 'לא הצלחנו לקשר בין מספר הזיהוי של רשימת הדיוור הזו לבין החשבון.'].freeze
28
+
29
+ def self.matches?(errors)
30
+ return false unless errors.keys == ['mailing_id']
31
+
32
+ mailing_id_errors = errors['mailing_id']
33
+ return false unless mailing_id_errors.size == 1
34
+
35
+ MATCHING_ERRORS.include?(mailing_id_errors.first)
36
+ end
26
37
  end
27
38
  end
28
39
  end
@@ -4,7 +4,7 @@ module ActionKitRest
4
4
  module VERSION
5
5
  MAJOR = 0
6
6
  MINOR = 4
7
- PATCH = 6
7
+ PATCH = 7
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.')
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'support/shared_contexts/stub_logger'
5
+
6
+ describe ActionKitRest::API do
7
+ include_context 'stub_logger'
8
+
9
+ subject { ActionKitRest::API.new(host: 'example.com', username: 'foo', password: 'bar') }
10
+
11
+ describe 'error detection' do
12
+ let(:request_body) { {some: 'data'} }
13
+
14
+ before :each do
15
+ stub_request(:post, 'https://example.com/rest/v1/something/')
16
+ .to_return(status: response_status, body: response_body,
17
+ headers: { content_type: 'application/json; charset=utf-8' })
18
+ end
19
+
20
+ context 'successful response' do
21
+ let(:response_status) { 200 }
22
+ let(:response_body) { '{"message": "good job!"}' }
23
+
24
+ it 'should not raise' do
25
+ subject.post_request('something/', request_body)
26
+ end
27
+ end
28
+
29
+ context '400 response' do
30
+ let(:response_status) { 400 }
31
+
32
+ context 'unable to associate mailing ID' do
33
+ let(:response_body) { '{"errors": {"mailing_id": ["Unable to associate this mailing ID with account."]}}' }
34
+
35
+ it 'should raise an InvalidAkidError' do
36
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::InvalidAkidError)
37
+ end
38
+ end
39
+
40
+ context 'unable to associate mailing ID error in Hebrew' do
41
+ let(:response_body) { '{"errors": {"mailing_id": ["לא הצלחנו לקשר בין מספר הזיהוי של רשימת הדיוור הזו לבין החשבון."]}}' }
42
+
43
+ it 'should raise an InvalidAkidError' do
44
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::InvalidAkidError)
45
+ end
46
+ end
47
+
48
+ context 'other error' do
49
+ let(:response_body) { '{"errors": {"zip": ["There is something wrong with your ZIP code!"]}}' }
50
+
51
+ it 'sould raise a ValidationError' do
52
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::ValidationError)
53
+ end
54
+ end
55
+ end
56
+
57
+ context '401 response' do
58
+ let(:response_status) { 401 }
59
+ let(:response_body) { '{"error": "Your API key is no good"}' }
60
+
61
+ it 'should raise an Unauthorized exception' do
62
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::Unauthorized)
63
+ end
64
+ end
65
+
66
+ context '404 response' do
67
+ let(:response_status) { 404 }
68
+ let(:response_body) { '{"error": "not found"}' }
69
+
70
+ it 'should raise a NotFound exception' do
71
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::NotFound)
72
+ end
73
+ end
74
+
75
+ context '500 response' do
76
+ let(:response_status) { 500 }
77
+
78
+ context 'Try Again Later message' do
79
+ let(:response_body) { '{"error": "Sorry, this request could not be processed. Please try again later."}' }
80
+
81
+ it 'should raise a TryAgainLater exception' do
82
+ expect{ subject.post_request('something/', request_body) }.to raise_error(ActionKitRest::Response::TryAgainLater)
83
+ end
84
+ end
85
+
86
+ context 'other error message' do
87
+ let(:response_body) { '{"error": "Something is wrong, we will fix it!"}' }
88
+
89
+ it 'should raise a StandardError' do
90
+ expect{ subject.post_request('something/', request_body) }.to raise_error(StandardError)
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_kit_rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Woodhull
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-09-29 00:00:00.000000000 Z
13
+ date: 2021-10-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: vertebrae
@@ -242,6 +242,7 @@ files:
242
242
  - spec/lib/action_kit_rest/actions/event_create_action_spec.rb
243
243
  - spec/lib/action_kit_rest/actions/event_signup_action_spec.rb
244
244
  - spec/lib/action_kit_rest/allowed_user_field_spec.rb
245
+ - spec/lib/action_kit_rest/api_spec.rb
245
246
  - spec/lib/action_kit_rest/logger_spec.rb
246
247
  - spec/lib/action_kit_rest/page_spec.rb
247
248
  - spec/lib/action_kit_rest/pages/event_campaign_page_spec.rb