usps-imis-api 1.0.0.pre.rc.7 → 1.0.0.pre.rc.9

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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +20 -2
  5. data/Readme.md +12 -2
  6. data/lib/usps/imis/api.rb +16 -12
  7. data/lib/usps/imis/business_object.rb +17 -8
  8. data/lib/usps/imis/data.rb +4 -0
  9. data/lib/usps/imis/error.rb +2 -0
  10. data/lib/usps/imis/mapper.rb +23 -0
  11. data/lib/usps/imis/panels/base_panel.rb +10 -0
  12. data/lib/usps/imis/query.rb +50 -18
  13. data/lib/usps/imis/requests.rb +7 -3
  14. data/lib/usps/imis/version.rb +1 -1
  15. data/lib/usps/imis.rb +5 -0
  16. data/spec/fixtures/vcr_cassettes/.keep +0 -0
  17. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_authorize/automatically_refreshes_an_expired_token.yml +67 -0
  18. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_imis_id_for/gets_the_iMIS_ID.yml +131 -0
  19. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_imis_id_for/with_a_query_error/wraps_errors.yml +67 -0
  20. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_inspect/does_not_show_the_token_instance_variable.yml +67 -0
  21. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_inspect/is_configured_to_exclude_the_token_instance_variable.yml +67 -0
  22. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/chains_with_on_to_a_single_block.yml +256 -0
  23. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/nests_on_and_with.yml +256 -0
  24. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/returns_a_BusinessObject_without_a_block.yml +67 -0
  25. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/sends_an_update_from_put.yml +256 -0
  26. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_put/sends_an_update.yml +256 -0
  27. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_put/when_receiving_a_response_error/wraps_the_error.yml +67 -0
  28. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_query/collects_all_query_results.yml +67 -0
  29. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/blocks_calling_imis_id_.yml +67 -0
  30. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/blocks_calling_imis_id_for.yml +67 -0
  31. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/sends_an_update_from_put.yml +256 -0
  32. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/sends_an_update_from_update.yml +256 -0
  33. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/uses_a_panel_correctly.yml +145 -0
  34. data/spec/fixtures/vcr_cassettes/Usps_Imis_Api/stores_the_initial_imis_id.yml +67 -0
  35. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/_put_field/submits_the_correct_update_request.yml +627 -0
  36. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_filter_fields/formats_fields_correctly.yml +67 -0
  37. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get/delegation_to_get_fields/delegates_to_get_fields.yml +67 -0
  38. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get/returns_multiple_values.yml +67 -0
  39. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get_field/returns_a_string_value.yml +67 -0
  40. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get_field/returns_an_integer_value.yml +67 -0
  41. data/spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get_fields/returns_multiple_values.yml +67 -0
  42. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/fetches_a_mapped_field.yml +158 -0
  43. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/raises_for_unmapped_updates.yml +67 -0
  44. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/supports_Hash_access_syntax.yml +158 -0
  45. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/supports_Hash_access_syntax_on_the_Api_directly.yml +158 -0
  46. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_update/raises_for_unmapped_updates.yml +67 -0
  47. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_update/sends_a_mapped_update.yml +256 -0
  48. data/spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/initialize_with_imis_id/stores_the_initial_imis_id.yml +67 -0
  49. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_BasePanel/requires_business_object_to_be_defined.yml +67 -0
  50. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_BasePanel/requires_payload_data_to_be_defined.yml +67 -0
  51. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get/loads_a_specific_object.yml +146 -0
  52. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get/returns_specific_fields.yml +146 -0
  53. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get_field/returns_a_specific_field.yml +146 -0
  54. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get_fields/returns_specific_fields.yml +146 -0
  55. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/interacts_with_records_correctly.yml +495 -0
  56. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/initialization_with_ID/can_initialize_with_an_iMIS_ID.yml +67 -0
  57. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Vsc/_get/loads_a_specific_object.yml +145 -0
  58. data/spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Vsc/handles_new_records_correctly.yml +319 -0
  59. data/spec/lib/usps/imis/api_spec.rb +4 -14
  60. data/spec/lib/usps/imis/business_object_spec.rb +63 -50
  61. data/spec/lib/usps/imis/data_spec.rb +9 -0
  62. data/spec/lib/usps/imis/mapper_spec.rb +1 -1
  63. data/spec/lib/usps/imis/panels/base_panel_spec.rb +1 -1
  64. data/spec/lib/usps/imis/panels/education_spec.rb +1 -1
  65. data/spec/lib/usps/imis/panels/vsc_spec.rb +1 -1
  66. data/spec/spec_helper.rb +40 -0
  67. metadata +44 -1
@@ -2,73 +2,86 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Usps::Imis::BusinessObject do
6
- let(:business_object) { described_class.new(api, 'Stub') }
7
- let(:api) { Usps::Imis::Api.new }
8
-
9
- before do
10
- allow(business_object).to receive(:raw_object).and_return(
11
- Usps::Imis::Data[
12
- 'Properties' => {
13
- '$values' => [
14
- { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
15
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
16
- { 'Name' => 'Stub String', 'Value' => 'something' }
17
- ]
18
- }
19
- ]
20
- )
5
+ describe Usps::Imis::BusinessObject, :vcr do
6
+ describe '#put_field' do
7
+ let(:business_object) { api.on('ABC_ASC_Individual_Demog') }
8
+ let(:api) { Usps::Imis::Api.new.with(31092) }
9
+
10
+ before { business_object.put_field('TotMMS', 15) }
11
+
12
+ it 'submits the correct update request' do
13
+ expect { business_object['TotMMS'] = 16 }.to change { business_object['TotMMS'] }.from(15).to(16)
14
+ end
21
15
  end
22
16
 
23
- describe '#get' do
24
- it 'returns multiple values' do
25
- expect(business_object.get('Stub String', 'Stub Integer')).to eq(['something', 42])
17
+ context 'with stubbed data' do
18
+ let(:business_object) { described_class.new(api, 'Stub') }
19
+ let(:api) { Usps::Imis::Api.new }
20
+
21
+ before do
22
+ allow(business_object).to receive(:raw_object).and_return(
23
+ Usps::Imis::Data[
24
+ 'Properties' => {
25
+ '$values' => [
26
+ { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
27
+ { 'Name' => 'Stub Integer', 'Value' => { '$value' => 42 } },
28
+ { 'Name' => 'Stub String', 'Value' => 'something' }
29
+ ]
30
+ }
31
+ ]
32
+ )
26
33
  end
27
34
 
28
- describe 'delegation to get_fields' do
29
- before { allow(business_object).to receive(:get_fields).with('Stub String', 'Stub Integer') }
35
+ describe '#get' do
36
+ it 'returns multiple values' do
37
+ expect(business_object.get('Stub String', 'Stub Integer')).to eq(['something', 42])
38
+ end
39
+
40
+ describe 'delegation to get_fields' do
41
+ before { allow(business_object).to receive(:get_fields).with('Stub String', 'Stub Integer') }
30
42
 
31
- it 'delegates to get_fields' do
32
- business_object.get('Stub String', 'Stub Integer')
43
+ it 'delegates to get_fields' do
44
+ business_object.get('Stub String', 'Stub Integer')
33
45
 
34
- expect(business_object).to have_received(:get_fields).with('Stub String', 'Stub Integer')
46
+ expect(business_object).to have_received(:get_fields).with('Stub String', 'Stub Integer')
47
+ end
35
48
  end
36
49
  end
37
- end
38
50
 
39
- describe '#get_field' do
40
- it 'returns a string value' do
41
- expect(business_object.get_field('Stub String')).to eq('something')
42
- end
51
+ describe '#get_field' do
52
+ it 'returns a string value' do
53
+ expect(business_object.get_field('Stub String')).to eq('something')
54
+ end
43
55
 
44
- it 'returns an integer value' do
45
- expect(business_object.get_field('Stub Integer')).to eq(42)
56
+ it 'returns an integer value' do
57
+ expect(business_object.get_field('Stub Integer')).to eq(42)
58
+ end
46
59
  end
47
- end
48
60
 
49
- describe '#get_fields' do
50
- it 'returns multiple values' do
51
- expect(business_object.get_fields('Stub String', 'Stub Integer')).to eq(['something', 42])
61
+ describe '#get_fields' do
62
+ it 'returns multiple values' do
63
+ expect(business_object.get_fields('Stub String', 'Stub Integer')).to eq(['something', 42])
64
+ end
52
65
  end
53
- end
54
66
 
55
- describe '#filter_fields' do
56
- let(:expected) do
57
- {
58
- 'Properties' => {
59
- '$values' => [
60
- { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
61
- { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
62
- { 'Name' => 'Stub String', 'Value' => 'other' }
63
- ]
67
+ describe '#filter_fields' do
68
+ let(:expected) do
69
+ {
70
+ 'Properties' => {
71
+ '$values' => [
72
+ { 'Name' => 'ID', 'Value' => { '$value' => '31092' } },
73
+ { 'Name' => 'Stub Integer', 'Value' => { '$value' => 43 } },
74
+ { 'Name' => 'Stub String', 'Value' => 'other' }
75
+ ]
76
+ }
64
77
  }
65
- }
66
- end
78
+ end
67
79
 
68
- it 'formats fields correctly' do
69
- updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
80
+ it 'formats fields correctly' do
81
+ updated = business_object.send(:filter_fields, 'Stub Integer' => 43, 'Stub String' => 'other')
70
82
 
71
- expect(updated).to eq(expected)
83
+ expect(updated).to eq(expected)
84
+ end
72
85
  end
73
86
  end
74
87
  end
@@ -36,6 +36,15 @@ describe Usps::Imis::Data do
36
36
  end
37
37
  end
38
38
 
39
+ describe '#[]=' do
40
+ it 'does not support setting values' do
41
+ expect { described_class.new[:something] = :another }.to raise_error(
42
+ Usps::Imis::Errors::ApiError,
43
+ '`Data` does not support setting values. If you need to modify it, call `.raw` on it.'
44
+ )
45
+ end
46
+ end
47
+
39
48
  describe '#inspect' do
40
49
  it 'generates the correct inspect string' do
41
50
  expect(data.inspect).to eq('#<Usps::Imis::Data entity="ABC_ASC_Individual_Demog" imis_id=31092>')
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Usps::Imis::Mapper do
5
+ describe Usps::Imis::Mapper, :vcr do
6
6
  let(:api) { described_class.new.api }
7
7
 
8
8
  describe 'initialize with imis_id' do
@@ -16,7 +16,7 @@ module Usps
16
16
  end
17
17
  end
18
18
 
19
- describe Usps::Imis::Panels::BasePanel do
19
+ describe Usps::Imis::Panels::BasePanel, :vcr do
20
20
  it 'requires #business_object to be defined' do
21
21
  expect { Usps::Imis::Panels::InvalidPanel.new.get(1) }.to raise_error(
22
22
  Usps::Imis::Errors::PanelUnimplementedError,
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Usps::Imis::Panels::Education do
5
+ describe Usps::Imis::Panels::Education, :vcr do
6
6
  describe 'api example' do
7
7
  let(:education) { described_class.new }
8
8
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Usps::Imis::Panels::Vsc do
5
+ describe Usps::Imis::Panels::Vsc, :vcr do
6
6
  let(:vsc) { described_class.new }
7
7
 
8
8
  let(:details) do
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,46 @@ require 'active_support/string_inquirer'
11
11
 
12
12
  ENV['TESTING'] = 'true'
13
13
 
14
+ require 'vcr'
15
+ require 'webmock/rspec'
16
+ WebMock.disable_net_connect!
17
+ record_mode = ENV['VCR'] ? ENV['VCR'].to_sym : :once
18
+ VCR.configure do |config|
19
+ config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
20
+ config.hook_into :webmock
21
+ config.default_cassette_options = {
22
+ record: record_mode,
23
+ match_requests_on: %i[method uri]
24
+ }
25
+ config.configure_rspec_metadata!
26
+
27
+ config.filter_sensitive_data('<USERNAME>') { ENV.fetch('IMIS_USERNAME') }
28
+ config.filter_sensitive_data('<USERNAME>') { CGI.escape(ENV.fetch('IMIS_USERNAME')) }
29
+
30
+ config.filter_sensitive_data('<PASSWORD>') { ENV.fetch('IMIS_PASSWORD') }
31
+ config.filter_sensitive_data('<PASSWORD>') { CGI.escape(ENV.fetch('IMIS_PASSWORD')) }
32
+
33
+ config.filter_sensitive_data('<ACCESS_TOKEN>') do |interaction|
34
+ if interaction.response.headers['Content-Type']&.first&.include?('application/json')
35
+ begin
36
+ response_body = JSON.parse(interaction.response.body)
37
+ response_body['access_token']
38
+ rescue JSON::ParserError
39
+ nil
40
+ end
41
+ end
42
+ end
43
+
44
+ config.filter_sensitive_data('<BEARER_TOKEN>') do |interaction|
45
+ if interaction.request.headers['Authorization']
46
+ auth_header = interaction.request.headers['Authorization'].first
47
+ if (match = auth_header.match(/^Bearer\s+([^,\s]+)/))
48
+ match.captures.first
49
+ end
50
+ end
51
+ end
52
+ end
53
+
14
54
  RSpec.configure do |config|
15
55
  # Enable flags like --only-failures and --next-failure
16
56
  config.example_status_persistence_file_path = 'tmp/.rspec_status'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: usps-imis-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.rc.7
4
+ version: 1.0.0.pre.rc.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Julian Fiander
@@ -66,6 +66,49 @@ files:
66
66
  - lib/usps/imis/query.rb
67
67
  - lib/usps/imis/requests.rb
68
68
  - lib/usps/imis/version.rb
69
+ - spec/fixtures/vcr_cassettes/.keep
70
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_authorize/automatically_refreshes_an_expired_token.yml
71
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_imis_id_for/gets_the_iMIS_ID.yml
72
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_imis_id_for/with_a_query_error/wraps_errors.yml
73
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_inspect/does_not_show_the_token_instance_variable.yml
74
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_inspect/is_configured_to_exclude_the_token_instance_variable.yml
75
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/chains_with_on_to_a_single_block.yml
76
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/nests_on_and_with.yml
77
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/returns_a_BusinessObject_without_a_block.yml
78
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_on/sends_an_update_from_put.yml
79
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_put/sends_an_update.yml
80
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_put/when_receiving_a_response_error/wraps_the_error.yml
81
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_query/collects_all_query_results.yml
82
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/blocks_calling_imis_id_.yml
83
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/blocks_calling_imis_id_for.yml
84
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/sends_an_update_from_put.yml
85
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/sends_an_update_from_update.yml
86
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/_with/uses_a_panel_correctly.yml
87
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Api/stores_the_initial_imis_id.yml
88
+ - spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/_put_field/submits_the_correct_update_request.yml
89
+ - spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_filter_fields/formats_fields_correctly.yml
90
+ - spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get/delegation_to_get_fields/delegates_to_get_fields.yml
91
+ - spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get/returns_multiple_values.yml
92
+ - spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get_field/returns_a_string_value.yml
93
+ - spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get_field/returns_an_integer_value.yml
94
+ - spec/fixtures/vcr_cassettes/Usps_Imis_BusinessObject/with_stubbed_data/_get_fields/returns_multiple_values.yml
95
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/fetches_a_mapped_field.yml
96
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/raises_for_unmapped_updates.yml
97
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/supports_Hash_access_syntax.yml
98
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_fetch/supports_Hash_access_syntax_on_the_Api_directly.yml
99
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_update/raises_for_unmapped_updates.yml
100
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/_update/sends_a_mapped_update.yml
101
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Mapper/initialize_with_imis_id/stores_the_initial_imis_id.yml
102
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Panels_BasePanel/requires_business_object_to_be_defined.yml
103
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Panels_BasePanel/requires_payload_data_to_be_defined.yml
104
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get/loads_a_specific_object.yml
105
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get/returns_specific_fields.yml
106
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get_field/returns_a_specific_field.yml
107
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/_get_fields/returns_specific_fields.yml
108
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/api_example/interacts_with_records_correctly.yml
109
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Education/initialization_with_ID/can_initialize_with_an_iMIS_ID.yml
110
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Vsc/_get/loads_a_specific_object.yml
111
+ - spec/fixtures/vcr_cassettes/Usps_Imis_Panels_Vsc/handles_new_records_correctly.yml
69
112
  - spec/lib/usps/imis/api_spec.rb
70
113
  - spec/lib/usps/imis/business_object_spec.rb
71
114
  - spec/lib/usps/imis/config_spec.rb