zuora-ruby 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rubocop.yml +11 -1
  4. data/README.md +101 -172
  5. data/bin/console +2 -2
  6. data/lib/utils/schema_model.rb +194 -0
  7. data/lib/zuora.rb +30 -72
  8. data/lib/zuora/calls/amend.rb +68 -0
  9. data/lib/zuora/calls/create.rb +9 -0
  10. data/lib/zuora/calls/delete.rb +20 -0
  11. data/lib/zuora/calls/generate.rb +22 -0
  12. data/lib/zuora/calls/login.rb +21 -0
  13. data/lib/zuora/calls/query.rb +15 -0
  14. data/lib/zuora/calls/subscribe.rb +75 -0
  15. data/lib/zuora/calls/update.rb +9 -0
  16. data/lib/zuora/calls/upsert.rb +29 -0
  17. data/lib/zuora/client.rb +84 -94
  18. data/lib/zuora/dispatcher.rb +45 -0
  19. data/lib/zuora/object.rb +5 -0
  20. data/lib/zuora/response.rb +50 -0
  21. data/lib/zuora/utils/envelope.rb +98 -0
  22. data/lib/zuora/version.rb +1 -4
  23. data/zuora_ruby.gemspec +10 -11
  24. metadata +57 -67
  25. data/lib/zuora/models.rb +0 -11
  26. data/lib/zuora/models/account.rb +0 -64
  27. data/lib/zuora/models/card_holder.rb +0 -54
  28. data/lib/zuora/models/contact.rb +0 -71
  29. data/lib/zuora/models/dirty.rb +0 -192
  30. data/lib/zuora/models/payment_method.rb +0 -1
  31. data/lib/zuora/models/payment_methods/credit_card.rb +0 -37
  32. data/lib/zuora/models/rate_plan.rb +0 -17
  33. data/lib/zuora/models/rate_plan_charge.rb +0 -119
  34. data/lib/zuora/models/subscription.rb +0 -80
  35. data/lib/zuora/models/tier.rb +0 -27
  36. data/lib/zuora/models/validation_predicates.rb +0 -29
  37. data/lib/zuora/resources.rb +0 -6
  38. data/lib/zuora/resources/accounts.rb +0 -20
  39. data/lib/zuora/resources/payment_methods.rb +0 -1
  40. data/lib/zuora/resources/payment_methods/credit_card.rb +0 -24
  41. data/lib/zuora/resources/subscriptions.rb +0 -17
  42. data/lib/zuora/serializers.rb +0 -1
  43. data/lib/zuora/serializers/attribute.rb +0 -35
  44. data/lib/zuora/serializers/noop.rb +0 -18
  45. data/zuora/fixtures/vcr_cassettes/account_create_.yml +0 -111
  46. data/zuora/fixtures/vcr_cassettes/account_update_.yml +0 -113
  47. data/zuora/fixtures/vcr_cassettes/subscription_create_.yml +0 -114
  48. data/zuora/fixtures/vcr_cassettes/subscription_update_.yml +0 -114
@@ -0,0 +1,45 @@
1
+ module Zuora
2
+ module Dispatcher
3
+ # Maps a SOAP call name and args to its corresponding class.
4
+
5
+ class << self
6
+ def create
7
+ Zuora::Calls::Create
8
+ end
9
+
10
+ def update
11
+ Zuora::Calls::Update
12
+ end
13
+
14
+ def login
15
+ Zuora::Calls::Login
16
+ end
17
+
18
+ def subscribe
19
+ Zuora::Calls::Subscribe
20
+ end
21
+
22
+ def amend
23
+ Zuora::Calls::Amend
24
+ end
25
+
26
+ def query
27
+ Zuora::Calls::Query
28
+ end
29
+
30
+ def delete
31
+ Zuora::Calls::Delete
32
+ end
33
+
34
+ def generate
35
+ Zuora::Calls::Generate
36
+ end
37
+
38
+ def method_missing
39
+ fail "Unknown SOAP API call name: #{call_name}.
40
+ Must be one of :create, :update, :login,
41
+ subscribe, :amend, or :delete."
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,5 @@
1
+ module Zuora
2
+ class Object < Hash
3
+ include Hashie::Extensions::MethodAccess
4
+ end
5
+ end
@@ -0,0 +1,50 @@
1
+ require 'active_support/core_ext/hash/conversions'
2
+
3
+ module Zuora
4
+ class Response
5
+ attr_reader :raw
6
+
7
+ # @param [Faraday::Response]
8
+ # @return [Zuora::Response]
9
+ def initialize(response)
10
+ @raw = response
11
+ end
12
+
13
+ # Convert XML body to object-like nested hash.
14
+ # @return [Hashie::Mash] object-like nested hash
15
+ def to_h
16
+ doc = Nokogiri::XML raw.body
17
+ hash = Hash.from_xml doc.to_xml
18
+ Hashie::Mash.new(symbolize_keys_deep(hash))
19
+ end
20
+
21
+ private
22
+
23
+ # Given a key, convert to symbol, removing XML namespace, if any.
24
+ # @param [String] key - a key, either "abc" or "abc:def"
25
+ # @return [Symbol]
26
+ def symbolize_key(key)
27
+ return key unless key.respond_to?(:split)
28
+ key.split(':').last.underscore.to_sym
29
+ end
30
+
31
+ # Recursively transforms a hash
32
+ # @param [Hash] hash
33
+ # @return [Hash]
34
+ def symbolize_keys_deep(hash)
35
+ return hash unless hash.is_a?(Hash)
36
+
37
+ Hash[hash.map do |key, value|
38
+ # if value is array, loop each element and recursively symbolize keys
39
+ if value.is_a? Array
40
+ value = value.map { |element| symbolize_keys_deep(element) }
41
+ # if value is hash, recursively symbolize keys
42
+ elsif value.is_a? Hash
43
+ value = symbolize_keys_deep(value)
44
+ end
45
+
46
+ [symbolize_key(key), value]
47
+ end]
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,98 @@
1
+ module Zuora
2
+ module Utils
3
+ module Envelope
4
+ CUSTOM_FIELD_STRING = '__c'.freeze
5
+
6
+ # @param [Callable] header - optional function of builder, rtns builder
7
+ # @param [Callable] body - optional function of builder, rtns builder
8
+ def self.xml(header, body)
9
+ Nokogiri::XML::Builder.new do |builder|
10
+ builder[:soapenv].Envelope(Zuora::NAMESPACES) do
11
+ builder[:soapenv].Header do
12
+ header.call builder
13
+ end if header
14
+ builder[:soapenv].Body do
15
+ body.call builder
16
+ end if body
17
+ end
18
+ end
19
+ end
20
+
21
+ # Takes a body, and returns an envelope with session token merged in
22
+ # @param [Callable] body - function of body
23
+ # @return [Nokogiri::XML::Builder]
24
+ def self.authenticated_xml(token, &body)
25
+ failure_message = 'Session token not set. Did you call authenticate?'
26
+ fail failure_message unless token.present?
27
+
28
+ header = lambda do |builder|
29
+ builder[:api].SessionHeader do
30
+ builder[:api].session(token)
31
+ end
32
+ builder
33
+ end
34
+
35
+ xml(header, body)
36
+ end
37
+
38
+ # Builds multiple fields
39
+ # @param [Nokogiri::XML::Builder] builder
40
+ # @param [Symbol] namespace
41
+ # @param [Hash] object
42
+ # @return nil
43
+ def self.build_fields(builder, namespace, object = {})
44
+ object.each do |key, value|
45
+ zuora_field_name = to_zuora_key(key)
46
+ builder[namespace].send(zuora_field_name, value) unless value.nil?
47
+ end
48
+ end
49
+
50
+ # Builds multiple objects
51
+ # @param [Nokogiri::XML::Builder] builder
52
+ # @param [Symbol] type
53
+ # @param [Array[Hash]] objects
54
+ # @return nil
55
+ def self.build_objects(builder, type, objects)
56
+ objects.each do |object|
57
+ builder[:api].zObjects('xsi:type' => "obj:#{type}") do
58
+ Zuora::Utils::Envelope.build_fields(builder, :obj, object)
59
+ end
60
+ end
61
+ end
62
+
63
+ # Converts from Ruby to Zuora key format.
64
+ # @param [Symbol] key - e.g. :some_key_name or :some_key_name__c
65
+ # @return [Symbol] - e.g. :SomeKeyName or :SomeKeyName__c
66
+ def self.to_zuora_key(key)
67
+ custom_field_matcher = Regexp.new CUSTOM_FIELD_STRING
68
+
69
+ matches = custom_field_matcher.match(key.to_s)
70
+ suffix = ''
71
+
72
+ if matches
73
+ key = key.to_s[0...-3].to_sym
74
+ suffix = CUSTOM_FIELD_STRING
75
+ end
76
+
77
+ key = transform_sym key, :camelize
78
+
79
+ [key.to_s, suffix].join.to_sym
80
+ end
81
+
82
+ # Converts from Zuora key format to Ruby format.
83
+ # @param [Symbol] key e.g. :SomeKeyName
84
+ # @return [Symbol] - e.g. :some_key_name
85
+ def self.from_zuora_key(key)
86
+ transform_sym key, :lower
87
+ end
88
+
89
+ # Transforms symbol as if were a string, using operation.
90
+ # Helper method for building specific symbol converters.
91
+ # @param [Symbol] - operation
92
+ # @param [Symbol] - symbol
93
+ def self.transform_sym(sym, operation)
94
+ sym.to_s.send(operation).to_sym
95
+ end
96
+ end
97
+ end
98
+ end
@@ -1,6 +1,3 @@
1
- # encoding: utf-8
2
-
3
- # Sets Zuora published version.
4
1
  module Zuora
5
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'.freeze
6
3
  end
@@ -29,25 +29,24 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ['lib']
30
30
 
31
31
  # Runtime
32
+ spec.add_runtime_dependency 'activesupport'
33
+ spec.add_runtime_dependency 'dotenv'
32
34
  spec.add_runtime_dependency 'faraday'
33
35
  spec.add_runtime_dependency 'faraday_middleware'
34
- spec.add_runtime_dependency 'activemodel', '~> 4.2'
35
-
36
- spec.add_runtime_dependency 'active_model_serializers', '~> 0.8'
37
- spec.add_runtime_dependency 'activesupport'
36
+ spec.add_runtime_dependency 'nokogiri', '~> 1.6'
37
+ spec.add_runtime_dependency 'hashie', '~> 3.4'
38
38
 
39
39
  # Development
40
40
  spec.add_development_dependency 'bundler'
41
+ spec.add_development_dependency 'byebug'
42
+ spec.add_development_dependency 'codeclimate-test-reporter'
43
+ spec.add_development_dependency 'factory_girl', '~> 4.0'
44
+ spec.add_development_dependency 'faker'
41
45
  spec.add_development_dependency 'rake'
42
46
  spec.add_development_dependency 'rspec'
43
47
  spec.add_development_dependency 'rspec-its'
44
- spec.add_development_dependency 'byebug'
45
- spec.add_development_dependency 'vcr'
46
- spec.add_development_dependency 'webmock'
47
- spec.add_development_dependency 'dotenv'
48
- spec.add_development_dependency 'codeclimate-test-reporter'
49
48
  spec.add_development_dependency 'rspec_junit_formatter', '0.2.2'
50
49
  spec.add_development_dependency 'rubocop'
51
- spec.add_development_dependency 'factory_girl', '~> 4.0'
52
- spec.add_development_dependency 'faker'
50
+ spec.add_development_dependency 'webmock'
51
+ spec.add_development_dependency 'vcr'
53
52
  end
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zuora-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Contactually Engineering
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-15 00:00:00.000000000 Z
11
+ date: 2016-02-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: faraday
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -25,7 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: faraday_middleware
28
+ name: dotenv
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
@@ -39,63 +39,63 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: activemodel
42
+ name: faraday
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '4.2'
47
+ version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '4.2'
54
+ version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: active_model_serializers
56
+ name: faraday_middleware
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - ">="
60
60
  - !ruby/object:Gem::Version
61
- version: '0.8'
61
+ version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - ">="
67
67
  - !ruby/object:Gem::Version
68
- version: '0.8'
68
+ version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: activesupport
70
+ name: nokogiri
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '1.6'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '1.6'
83
83
  - !ruby/object:Gem::Dependency
84
- name: bundler
84
+ name: hashie
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
90
- type: :development
89
+ version: '3.4'
90
+ type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '3.4'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rake
98
+ name: bundler
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rspec
112
+ name: byebug
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rspec-its
126
+ name: codeclimate-test-reporter
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -137,21 +137,21 @@ dependencies:
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  - !ruby/object:Gem::Dependency
140
- name: byebug
140
+ name: factory_girl
141
141
  requirement: !ruby/object:Gem::Requirement
142
142
  requirements:
143
- - - ">="
143
+ - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '0'
145
+ version: '4.0'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
- - - ">="
150
+ - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '0'
152
+ version: '4.0'
153
153
  - !ruby/object:Gem::Dependency
154
- name: vcr
154
+ name: faker
155
155
  requirement: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
@@ -165,7 +165,7 @@ dependencies:
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
167
  - !ruby/object:Gem::Dependency
168
- name: webmock
168
+ name: rake
169
169
  requirement: !ruby/object:Gem::Requirement
170
170
  requirements:
171
171
  - - ">="
@@ -179,7 +179,7 @@ dependencies:
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  - !ruby/object:Gem::Dependency
182
- name: dotenv
182
+ name: rspec
183
183
  requirement: !ruby/object:Gem::Requirement
184
184
  requirements:
185
185
  - - ">="
@@ -193,7 +193,7 @@ dependencies:
193
193
  - !ruby/object:Gem::Version
194
194
  version: '0'
195
195
  - !ruby/object:Gem::Dependency
196
- name: codeclimate-test-reporter
196
+ name: rspec-its
197
197
  requirement: !ruby/object:Gem::Requirement
198
198
  requirements:
199
199
  - - ">="
@@ -235,21 +235,21 @@ dependencies:
235
235
  - !ruby/object:Gem::Version
236
236
  version: '0'
237
237
  - !ruby/object:Gem::Dependency
238
- name: factory_girl
238
+ name: webmock
239
239
  requirement: !ruby/object:Gem::Requirement
240
240
  requirements:
241
- - - "~>"
241
+ - - ">="
242
242
  - !ruby/object:Gem::Version
243
- version: '4.0'
243
+ version: '0'
244
244
  type: :development
245
245
  prerelease: false
246
246
  version_requirements: !ruby/object:Gem::Requirement
247
247
  requirements:
248
- - - "~>"
248
+ - - ">="
249
249
  - !ruby/object:Gem::Version
250
- version: '4.0'
250
+ version: '0'
251
251
  - !ruby/object:Gem::Dependency
252
- name: faker
252
+ name: vcr
253
253
  requirement: !ruby/object:Gem::Requirement
254
254
  requirements:
255
255
  - - ">="
@@ -281,33 +281,23 @@ files:
281
281
  - bin/console
282
282
  - bin/setup
283
283
  - circle.yml
284
+ - lib/utils/schema_model.rb
284
285
  - lib/zuora.rb
286
+ - lib/zuora/calls/amend.rb
287
+ - lib/zuora/calls/create.rb
288
+ - lib/zuora/calls/delete.rb
289
+ - lib/zuora/calls/generate.rb
290
+ - lib/zuora/calls/login.rb
291
+ - lib/zuora/calls/query.rb
292
+ - lib/zuora/calls/subscribe.rb
293
+ - lib/zuora/calls/update.rb
294
+ - lib/zuora/calls/upsert.rb
285
295
  - lib/zuora/client.rb
286
- - lib/zuora/models.rb
287
- - lib/zuora/models/account.rb
288
- - lib/zuora/models/card_holder.rb
289
- - lib/zuora/models/contact.rb
290
- - lib/zuora/models/dirty.rb
291
- - lib/zuora/models/payment_method.rb
292
- - lib/zuora/models/payment_methods/credit_card.rb
293
- - lib/zuora/models/rate_plan.rb
294
- - lib/zuora/models/rate_plan_charge.rb
295
- - lib/zuora/models/subscription.rb
296
- - lib/zuora/models/tier.rb
297
- - lib/zuora/models/validation_predicates.rb
298
- - lib/zuora/resources.rb
299
- - lib/zuora/resources/accounts.rb
300
- - lib/zuora/resources/payment_methods.rb
301
- - lib/zuora/resources/payment_methods/credit_card.rb
302
- - lib/zuora/resources/subscriptions.rb
303
- - lib/zuora/serializers.rb
304
- - lib/zuora/serializers/attribute.rb
305
- - lib/zuora/serializers/noop.rb
296
+ - lib/zuora/dispatcher.rb
297
+ - lib/zuora/object.rb
298
+ - lib/zuora/response.rb
299
+ - lib/zuora/utils/envelope.rb
306
300
  - lib/zuora/version.rb
307
- - zuora/fixtures/vcr_cassettes/account_create_.yml
308
- - zuora/fixtures/vcr_cassettes/account_update_.yml
309
- - zuora/fixtures/vcr_cassettes/subscription_create_.yml
310
- - zuora/fixtures/vcr_cassettes/subscription_update_.yml
311
301
  - zuora_ruby.gemspec
312
302
  homepage: https://github.com/contactually/zuora-ruby
313
303
  licenses: