rock_rms 8.5.0 → 8.6.0

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: 19e99238273531c1c5f3be2e95cb7d10d3b5c025043a11157e10ae7f01b984a5
4
- data.tar.gz: 4d5e4758dac63b7174305d2ed3d576b60e298c30d4f5b07f7a90b5bb2d76841a
3
+ metadata.gz: a9c04e1fe039a7d8bfadb17f09ba3bae6c9da6519b501dcaa0e911fd590b81df
4
+ data.tar.gz: 4ad41691163a7479d9b80387f3d36072a487238cbc1235844e5a718ff2452fd8
5
5
  SHA512:
6
- metadata.gz: 60ae0f673bad03a9a86eab352448a176b7ad8b48fd63c7d48a4571f7fdd14fda6b402ca06e0de9bd8c97960877b9bafab570f2bcd02b081e6205c81ec84d0b15
7
- data.tar.gz: 3cec7a048167ec96a7fa20033a28c768056eca3ec940ec8ef5e491fd1852cba804abbf93004a39bef26ad418e7f18d7321c7befe72bbfe6028b8c16a699dae16
6
+ metadata.gz: 7483f4c398437d73dcfb1daa0bbd1fa9cbea89a52bfb2ed8b5fee65f3567048564d6634b544d59aec684c78d6879d749428d1d2f7f37a0c991836e54c4f881f3
7
+ data.tar.gz: e53e8d7a856f72fd85b4bec5fe21c7f95bfc59d9d564417262076d1a082ec793c4a565dd9a9ada1cf80e80d9b0b54f57defcd0825edc1d935fb433c989c47187
data/README.md CHANGED
@@ -22,12 +22,19 @@ Add this line to your application's Gemfile:
22
22
 
23
23
  ### Usage
24
24
  ````ruby
25
+ # Authenticating with username and password
25
26
  client = RockRMS::Client.new(
26
27
  url: ...,
27
28
  username: ...,
28
29
  password: ...,
29
30
  )
30
31
 
32
+ # Authenticating with authorization token
33
+ client = RockRMS::Client.new(
34
+ url: ...,
35
+ authorization_token: ...,
36
+ )
37
+
31
38
  # Find a specific person
32
39
  client.find_person_by_email('gob@bluthco.com')
33
40
  client.find_person_by_name('Tobias Funke')
@@ -4,11 +4,13 @@ require 'faraday/multipart'
4
4
 
5
5
  Dir[File.expand_path('../resources/*.rb', __FILE__)].each { |f| require f }
6
6
  require File.expand_path('../response/base.rb', __FILE__)
7
+ require File.expand_path('../transform_hash_keys.rb', __FILE__)
7
8
  require File.expand_path('../recurring_frequencies.rb', __FILE__)
8
9
  Dir[File.expand_path('../response/*.rb', __FILE__)].each { |f| require f }
9
10
 
10
11
  module RockRMS
11
12
  class Client
13
+ include TransformHashKeys
12
14
  include RecurringFrequencies
13
15
  include RockRMS::Client::Attribute
14
16
  include RockRMS::Client::AttributeValue
@@ -46,16 +48,21 @@ module RockRMS
46
48
  include RockRMS::Client::WorkflowActivityType
47
49
  include RockRMS::Client::WorkflowType
48
50
 
49
- attr_reader :url, :username, :password, :logger, :cookie, :connection, :adapter, :ssl
51
+ attr_reader :url, :username, :password, :logger, :cookie, :connection, :adapter, :ssl, :authorization_token
52
+
53
+ def initialize(url:, username: nil, password: nil, authorization_token: nil, logger: true, adapter: Faraday.default_adapter, ssl: nil)
54
+ if username.nil? && password.nil? && authorization_token.nil?
55
+ raise ArgumentError, 'either username and password or authorization_token is required'
56
+ end
50
57
 
51
- def initialize(url:, username:, password:, logger: true, adapter: Faraday.default_adapter, ssl: nil)
52
58
  @url = "#{url}/api/"
53
- @username = username
54
- @password = password
59
+ @username = username unless authorization_token
60
+ @password = password unless authorization_token
61
+ @authorization_token = authorization_token unless username && password
55
62
  @logger = logger
56
63
  @adapter = adapter
57
64
  @ssl = ssl
58
- @cookie = auth['set-cookie']
65
+ @cookie = auth['set-cookie'] unless auth.nil?
59
66
  end
60
67
 
61
68
  def delete(path, options = {})
@@ -81,6 +88,8 @@ module RockRMS
81
88
  private
82
89
 
83
90
  def auth
91
+ return nil if username.nil? && password.nil?
92
+
84
93
  begin
85
94
  auth_request('Auth/Login')
86
95
  rescue Faraday::ParsingError => e
@@ -108,6 +117,7 @@ module RockRMS
108
117
  }
109
118
 
110
119
  headers['Cookie'] = cookie if cookie
120
+ headers['Authorization-Token'] = authorization_token if authorization_token
111
121
 
112
122
  client_opts = {
113
123
  url: url,
@@ -25,6 +25,23 @@ module RockRMS
25
25
  )
26
26
  end
27
27
 
28
+ #
29
+ # address_format
30
+ # {
31
+ # street1:,
32
+ # street2:,
33
+ # city:,
34
+ # state:,
35
+ # postal_code:,
36
+ # country:,
37
+ # }
38
+ #
39
+ def save_group_address(group_id:, location_type_id:, address:)
40
+ url_params = TransformHashKeys.camelize_keys(address)
41
+
42
+ put("Groups/SaveAddress/#{group_id}/#{location_type_id}?#{URI.encode_www_form(url_params)}")
43
+ end
44
+
28
45
  private
29
46
 
30
47
  def group_path(id = nil)
@@ -58,7 +58,8 @@ module RockRMS
58
58
  transaction_code: nil,
59
59
  transaction_type_value_id: nil,
60
60
  authorized_person_id: nil,
61
- date: nil
61
+ date: nil,
62
+ foreign_currency_code_value_id: nil
62
63
  )
63
64
  options = {}
64
65
 
@@ -71,6 +72,7 @@ module RockRMS
71
72
  options['TransactionCode'] = transaction_code if transaction_code
72
73
  options['AuthorizedPersonAliasId'] = authorized_person_id if authorized_person_id
73
74
  options['TransactionDateTime'] = date if date
75
+ options['ForeignCurrencyCodeValueId'] = foreign_currency_code_value_id if foreign_currency_code_value_id
74
76
 
75
77
  patch(transaction_path(id), options)
76
78
  end
@@ -11,7 +11,8 @@ module RockRMS
11
11
  giving_group_id: 'GivingGroupId',
12
12
  alias_id: 'PrimaryAliasId',
13
13
  connection_status_value_id: 'ConnectionStatusValueId',
14
- record_type_value_id: 'RecordTypeValueId'
14
+ record_type_value_id: 'RecordTypeValueId',
15
+ primary_family_id: 'PrimaryFamilyId',
15
16
  }.freeze
16
17
 
17
18
  def format_single(data)
@@ -0,0 +1,11 @@
1
+ module TransformHashKeys
2
+ def self.camelize_keys(hash)
3
+ hash
4
+ .filter { |_, v| v }
5
+ .transform_keys { |k| camelize(k) }
6
+ end
7
+
8
+ def self.camelize(term)
9
+ term.to_s.gsub(/(?:^|_+)([^_])/) { $1.upcase }.tap { |s| s[0] = s[0].downcase }
10
+ end
11
+ end
@@ -1,3 +1,3 @@
1
1
  module RockRMS
2
- VERSION = '8.5.0'.freeze
2
+ VERSION = '8.6.0'.freeze
3
3
  end
@@ -9,6 +9,14 @@ RSpec.describe RockRMS::Client do
9
9
  }
10
10
  end
11
11
  let(:attrs_without_logging) { attrs.merge(logger: false) }
12
+ let(:attrs_without_authentication) do
13
+ {
14
+ url: 'http://some-rock-uri.com',
15
+ username: nil,
16
+ password: nil,
17
+ authorization_token: nil
18
+ }
19
+ end
12
20
 
13
21
  subject(:client) { described_class.new(**attrs_without_logging) }
14
22
  let(:noisy_client) { described_class.new(**attrs) }
@@ -19,14 +27,9 @@ RSpec.describe RockRMS::Client do
19
27
  .to raise_error(ArgumentError, /url/)
20
28
  end
21
29
 
22
- it 'requries `username` param' do
23
- expect { described_class.new }
24
- .to raise_error(ArgumentError, /username/)
25
- end
26
-
27
- it 'requries `password` param' do
28
- expect { described_class.new }
29
- .to raise_error(ArgumentError, /password/)
30
+ it 'requries either `username` and `password` params or `authorization_token` param' do
31
+ expect { described_class.new(attrs_without_authentication) }
32
+ .to raise_error(ArgumentError, /username and password or authorization_token/)
30
33
  end
31
34
 
32
35
  context 'url' do
@@ -107,4 +107,35 @@ RSpec.describe RockRMS::Client::Group, type: :model do
107
107
  client.list_families_for_person(123)
108
108
  end
109
109
  end
110
+
111
+
112
+ describe '#save_address' do
113
+ context 'arguments' do
114
+ it 'require `group_id`' do
115
+ expect { client.save_group_address }
116
+ .to raise_error(ArgumentError, /group_id/)
117
+ end
118
+
119
+ it 'require `location_type_id`' do
120
+ expect { client.save_group_address }
121
+ .to raise_error(ArgumentError, /location_type_id/)
122
+ end
123
+
124
+ it 'require `address`' do
125
+ expect { client.save_group_address }
126
+ .to raise_error(ArgumentError, /address/)
127
+ end
128
+
129
+ end
130
+
131
+ subject(:resource) do
132
+ client.save_group_address(group_id: 1, location_type_id: 1, address: { street1: '123 Main St', postal_code: '12345' })
133
+ end
134
+
135
+ it 'passes options' do
136
+ expect(client).to receive(:put)
137
+ .with("Groups/SaveAddress/1/1?street1=123+Main+St&postalCode=12345").and_call_original
138
+ resource
139
+ end
140
+ end
110
141
  end
File without changes
@@ -76,6 +76,15 @@ class RockMock < Sinatra::Base
76
76
  end
77
77
  end
78
78
 
79
+ # PUT requests
80
+ {
81
+ group_save_address: 'Groups/SaveAddress/:group_id/:location_type_id',
82
+ }.each do |json, end_point|
83
+ put "/api/#{end_point}" do
84
+ json_response 204, "#{json}.json"
85
+ end
86
+ end
87
+
79
88
  # PATCH requests
80
89
  [
81
90
  'FinancialBatches/:id',
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rock_rms
3
3
  version: !ruby/object:Gem::Version
4
- version: 8.5.0
4
+ version: 8.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Brooks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-04-12 00:00:00.000000000 Z
11
+ date: 2023-04-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -270,6 +270,7 @@ files:
270
270
  - lib/rock_rms/response/workflow_action_type.rb
271
271
  - lib/rock_rms/response/workflow_activity_type.rb
272
272
  - lib/rock_rms/response/workflow_type.rb
273
+ - lib/rock_rms/transform_hash_keys.rb
273
274
  - lib/rock_rms/version.rb
274
275
  - rock_rms.gemspec
275
276
  - spec/rock_rms/client_spec.rb
@@ -340,6 +341,7 @@ files:
340
341
  - spec/support/fixtures/group.json
341
342
  - spec/support/fixtures/group_locations.json
342
343
  - spec/support/fixtures/group_members.json
344
+ - spec/support/fixtures/group_save_address.json
343
345
  - spec/support/fixtures/groups.json
344
346
  - spec/support/fixtures/groups_with_campus.json
345
347
  - spec/support/fixtures/groups_with_locations.json