asaas-ruby 0.1.11 → 0.2.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
  SHA1:
3
- metadata.gz: bfddda4e72ece3f55953b93af65e9143f62a42b7
4
- data.tar.gz: 623dfce936dfe6404a47257c74a8680d206c08b2
3
+ metadata.gz: 4eee912a1b783b7b059b127151602ab3ff769bd7
4
+ data.tar.gz: 4e485d1ec8d0f2c711f897ffadfed0e6499b2245
5
5
  SHA512:
6
- metadata.gz: bb15e4c2f8a2cea35dd51094f5da56b6e4890582ffdd74e15cbdbf1e85d068d42e75f8701cd4bf55d287ab35e4c68eb8879f4c052c0e9977f42883a1d37a1d71
7
- data.tar.gz: 0033b7d1f5c0e14950dd20c43df5cb9dfbdb77d47970c2da824ec7556c33354cca5a821bfc2fdd73b95539d1bf715d339ce5fbcc007f1c3c3cb4e2fd32430fdb
6
+ metadata.gz: 38ce6fcb65f4610b03511cc5a7d5abd07ae496c2635c27db8fc76b4abead0923897eb41d557d3a2b71514aa19e9dd3aca2a1f041c755043d8289824c08a5e516
7
+ data.tar.gz: 2c70d65f60379e1c34ce2a86d73ee14f154f18386ecd3eb291c5230e55817436806a02f4358d8718df08e2d799375d7ddd9c2436adf290413d4032665f07c418
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/asaas-ruby.gemspec CHANGED
@@ -24,6 +24,9 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_dependency "activesupport", "~> 4.2"
26
26
  spec.add_dependency "virtus", '~> 1.0', "~> 1.0.5"
27
+ spec.add_dependency "dry-types"
28
+ spec.add_dependency "dry-struct"
29
+ spec.add_dependency "dry-monads"
27
30
  spec.add_dependency "typhoeus", '~> 1.0', "~> 1.0.2"
28
31
  spec.add_dependency "rest-client", '~> 1.8', "~> 1.8.0"
29
32
  spec.add_dependency "awesome_print", '~> 1.6', "~> 1.6.1"
data/lib/asaas-ruby.rb CHANGED
@@ -3,16 +3,28 @@ require 'active_support'
3
3
  require 'active_support/inflector'
4
4
  require 'rest-client'
5
5
  require 'typhoeus'
6
+ require 'dry-types'
7
+ require 'dry-struct'
6
8
  require 'asaas/version'
9
+ require 'asaas/types'
7
10
  require 'virtus'
8
11
  require 'json'
9
12
 
13
+
10
14
  module Asaas
11
15
  autoload :Entity, 'asaas/entity'
12
16
  autoload :Configuration, 'asaas/configuration'
13
17
  autoload :Api, 'asaas/api'
14
18
  autoload :Client, 'asaas/client'
15
19
 
20
+ autoload :Model, 'asaas/models/model'
21
+ autoload :Customer, 'asaas/models/customer'
22
+ autoload :Payment, 'asaas/models/payment'
23
+ autoload :Discount, 'asaas/models/discount'
24
+ autoload :Interest, 'asaas/models/interest'
25
+ autoload :Fine, 'asaas/models/fine'
26
+ autoload :Webhook, 'asaas/models/webhook'
27
+
16
28
  class << self
17
29
 
18
30
  def setup(&block)
@@ -2,8 +2,8 @@ module Asaas
2
2
  module Api
3
3
  class Account < Asaas::Api::Base
4
4
 
5
- def initialize(token)
6
- super(token, '/accounts')
5
+ def initialize(token, api_version)
6
+ super(token, api_version, '/accounts')
7
7
  end
8
8
 
9
9
  end
@@ -9,10 +9,12 @@ module Asaas
9
9
  attr_reader :token
10
10
  attr_accessor :route
11
11
 
12
- def initialize(client_token, route = nil)
12
+ def initialize(client_token, api_version, route = nil)
13
13
  @token = client_token
14
14
  @route = route
15
- @endpoint = Asaas::Configuration.get_endpoint
15
+ @api_version = api_version || Asaas::Configuration.api_version
16
+ @endpoint = Asaas::Configuration.get_endpoint(api_version)
17
+ puts @endpoint
16
18
  end
17
19
 
18
20
  def extract_meta(meta)
@@ -74,13 +76,17 @@ module Asaas
74
76
  end
75
77
 
76
78
  def convert_data_to_entity(type)
77
- "Asaas::Entity::#{type.capitalize}".constantize
79
+ if @api_version == 2
80
+ "Asaas::Entity::#{type.capitalize}".constantize
81
+ else
82
+ "Asaas::#{type.capitalize}".constantize
83
+ end
78
84
  rescue
79
85
  Asaas::Entity::Base
80
86
  end
81
87
 
82
88
  def request(method, params = {}, body = nil)
83
- body = body && body.try(:attributes)
89
+ body = body && body.respond_to?(:attributes) && body.attributes
84
90
  @response = Typhoeus::Request.new(
85
91
  parse_url(params.fetch(:id, false)),
86
92
  method: method,
@@ -93,7 +99,6 @@ module Asaas
93
99
  def response_success
94
100
  entity = nil
95
101
  hash = JSON.parse(@response.body)
96
-
97
102
  if hash.fetch("object", false) === "list"
98
103
  entity = Asaas::Entity::Meta.new(hash)
99
104
  else
@@ -2,8 +2,8 @@ module Asaas
2
2
  module Api
3
3
  class City < Asaas::Api::Base
4
4
 
5
- def initialize(token)
6
- super(token, '/cities')
5
+ def initialize(token, api_version)
6
+ super(token, api_version, '/cities')
7
7
  end
8
8
 
9
9
  end
@@ -2,8 +2,8 @@ module Asaas
2
2
  module Api
3
3
  class Customer < Asaas::Api::Base
4
4
 
5
- def initialize(token)
6
- super(token, '/customers')
5
+ def initialize(token, api_version)
6
+ super(token, api_version, '/customers')
7
7
  end
8
8
 
9
9
  end
@@ -2,8 +2,8 @@ module Asaas
2
2
  module Api
3
3
  class Notification < Asaas::Api::Base
4
4
 
5
- def initialize(token)
6
- super(token, '/notifications')
5
+ def initialize(token, api_version)
6
+ super(token, api_version, '/notifications')
7
7
  end
8
8
 
9
9
  end
@@ -2,8 +2,8 @@ module Asaas
2
2
  module Api
3
3
  class Payment < Asaas::Api::Base
4
4
 
5
- def initialize(token)
6
- super(token, '/payments')
5
+ def initialize(token, api_version)
6
+ super(token, api_version, '/payments')
7
7
  end
8
8
 
9
9
  end
@@ -2,8 +2,8 @@ module Asaas
2
2
  module Api
3
3
  class Subscription < Asaas::Api::Base
4
4
 
5
- def initialize(token)
6
- super(token, '/subscriptions')
5
+ def initialize(token, api_version)
6
+ super(token, api_version, '/subscriptions')
7
7
  end
8
8
 
9
9
  end
data/lib/asaas/client.rb CHANGED
@@ -3,32 +3,33 @@ module Asaas
3
3
 
4
4
  attr_reader :token
5
5
 
6
- def initialize(token = nil)
6
+ def initialize(token = nil, api_version = nil)
7
7
  @token = token || Asaas::Configuration.token
8
+ @api_version = api_version || Asaas::Configuration.api_version
8
9
  end
9
10
 
10
11
  def accounts
11
- @accounts ||= Asaas::Api::Account.new(@token)
12
+ @accounts ||= Asaas::Api::Account.new(@token, @api_version)
12
13
  end
13
14
 
14
15
  def cities
15
- @cities ||= Asaas::Api::City.new(@token)
16
+ @cities ||= Asaas::Api::City.new(@token, @api_version)
16
17
  end
17
18
 
18
19
  def customers
19
- @customers ||= Asaas::Api::Customer.new(@token)
20
+ @customers ||= Asaas::Api::Customer.new(@token, @api_version)
20
21
  end
21
22
 
22
23
  def notifications
23
- @notifications ||= Asaas::Api::Notification.new(@token)
24
+ @notifications ||= Asaas::Api::Notification.new(@token, @api_version)
24
25
  end
25
26
 
26
27
  def payments
27
- @payments ||= Asaas::Api::Payment.new(@token)
28
+ @payments ||= Asaas::Api::Payment.new(@token, @api_version)
28
29
  end
29
30
 
30
31
  def subscriptions
31
- @subscriptions ||= Asaas::Api::Subscription.new(@token)
32
+ @subscriptions ||= Asaas::Api::Subscription.new(@token, @api_version)
32
33
  end
33
34
 
34
35
  end
@@ -1,18 +1,32 @@
1
1
  module Asaas
2
2
  module Configuration
3
3
 
4
- mattr_accessor :staging_endpoint do
5
- 'http://homolog.asaas.com/api/v2'
6
- end
4
+ ENDPOINT_PRODUCTION = {
5
+ v2: 'https://www.asaas.com/api/v2',
6
+ v3: 'https://www.asaas.com/api/v3',
7
+ }
7
8
 
8
- mattr_accessor :production_endpoint do
9
- 'https://www.asaas.com/api/v2'
10
- end
9
+ ENDPOINT_HOMOLOG = {
10
+ v2: 'https://homolog.asaas.com/api/v2',
11
+ v3: 'https://homolog.asaas.com/api/v3',
12
+ }
11
13
 
12
14
  mattr_accessor :production do
13
15
  false
14
16
  end
15
17
 
18
+ mattr_accessor :webhook_url do
19
+ nil
20
+ end
21
+
22
+ mattr_accessor :webhook_email do
23
+ nil
24
+ end
25
+
26
+ mattr_accessor :api_version do
27
+ 3
28
+ end
29
+
16
30
  mattr_accessor :token
17
31
 
18
32
  mattr_accessor :debug do
@@ -26,11 +40,12 @@ module Asaas
26
40
  self
27
41
  end
28
42
 
29
- def get_endpoint
43
+ def get_endpoint(api_version = nil)
44
+ api_version ||= Asaas::Configuration.api_version
30
45
  if production
31
- production_endpoint
46
+ ENDPOINT_PRODUCTION[:"v#{api_version}"]
32
47
  else
33
- staging_endpoint
48
+ ENDPOINT_HOMOLOG[:"v#{api_version}"]
34
49
  end
35
50
  end
36
51
 
@@ -38,7 +53,7 @@ module Asaas
38
53
  if production
39
54
  :production
40
55
  else
41
- :staging
56
+ :homolog
42
57
  end
43
58
  end
44
59
 
@@ -0,0 +1,23 @@
1
+ module Asaas
2
+ class Customer < Model
3
+ transform_keys(&:to_sym)
4
+
5
+ attribute :id, Types::Coercible::String.optional.default(nil)
6
+ attribute :name, Types::Coercible::String
7
+ attribute :cpfCnpj, Types::Coercible::String
8
+ attribute :email, Types::Coercible::String.optional.default(nil)
9
+ attribute :phone, Types::Coercible::String.optional.default(nil)
10
+ attribute :mobilePhone, Types::Coercible::String.optional.default(nil)
11
+ attribute :address, Types::Coercible::String.optional.default(nil)
12
+ attribute :addressNumber, Types::Coercible::String.optional.default(nil)
13
+ attribute :complement, Types::Coercible::String.optional.default(nil)
14
+ attribute :province, Types::Coercible::String.optional.default(nil)
15
+ attribute :postalCode, Types::Coercible::String.optional.default(nil)
16
+ attribute :externalReference, Types::Coercible::String.optional.default(nil)
17
+ attribute :notificationDisabled, Types::Bool.optional.default(false)
18
+ attribute :additionalEmails, Types::Coercible::String.optional.default(nil)
19
+ attribute :municipalInscription, Types::Coercible::String.optional.default(nil)
20
+ attribute :stateInscription, Types::Coercible::String.optional.default(nil)
21
+ attribute :groupName, Types::Coercible::String.optional.default(nil)
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ module Asaas
2
+ class Discount < Model
3
+ transform_keys(&:to_sym)
4
+
5
+ DiscountTypes = Types::Strict::String.enum('FIXED', 'PERCENTAGE')
6
+ attribute :value, Types::Coercible::Decimal
7
+ attribute :dueDateLimitDays, Types::Coercible::Integer.optional.default(0)
8
+ attribute :type, DiscountTypes
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Asaas
2
+ class Fine < Model
3
+ attribute :value, Types::Coercible::Decimal
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Asaas
2
+ class Interest < Model
3
+ attribute :value, Types::Coercible::Decimal
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Asaas
2
+ class Model < Dry::Struct
3
+ transform_keys(&:to_sym)
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ module Asaas
2
+ class Payment < Model
3
+ BillingTypes = Types::Strict::String.enum('BOLETO', 'CREDIT_CARD', 'UNDEFINED')
4
+
5
+ attribute :id, Types::Coercible::String.optional.default(nil)
6
+ attribute :customer, Types::Coercible::String
7
+ attribute :billingType, BillingTypes.optional.default(nil)
8
+ attribute :value, Types::Coercible::Decimal.optional.default(nil)
9
+ attribute :dueDate, Types::Coercible::String.optional.default(nil)
10
+ attribute :description, Types::Coercible::String.optional.default(nil)
11
+ attribute :externalReference, Types::Coercible::String.optional.default(nil)
12
+ attribute :installmentCount, Types::Coercible::String.optional.default(nil)
13
+ attribute :installmentValue, Types::Coercible::String.optional.default(nil)
14
+ attribute :discount, Discount.optional.default(nil)
15
+ attribute :interest, Interest.optional.default(nil)
16
+ attribute :fine, Fine.optional.default(nil)
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ module Asaas
2
+ class Webhook < Model
3
+ attribute :id, Types::Coercible::String.optional.default(nil)
4
+ attribute :url, Types::Coercible::String.optional.default { Asaas::Configuration.webhook_url }
5
+ attribute :email, Types::Coercible::String.optional.default { Asaas::Configuration.webhook_email }
6
+ attribute :apiVersion, Types::Coercible::Integer.optional.default {Asaas::Configuration.api_version }
7
+ attribute :enabled, Types::Bool.optional.default(nil)
8
+ attribute :interrupted, Types::Bool.optional.default(nil)
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ Dry::Types.load_extensions(:maybe)
2
+
3
+ module Types
4
+ include Dry::Types.module
5
+ end
data/lib/asaas/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Asaas
2
- VERSION = "0.1.11"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asaas-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marcos Junior
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-24 00:00:00.000000000 Z
11
+ date: 2019-01-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -86,6 +86,48 @@ dependencies:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
88
  version: 1.0.5
89
+ - !ruby/object:Gem::Dependency
90
+ name: dry-types
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ - !ruby/object:Gem::Dependency
104
+ name: dry-struct
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: dry-monads
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
89
131
  - !ruby/object:Gem::Dependency
90
132
  name: typhoeus
91
133
  requirement: !ruby/object:Gem::Requirement
@@ -154,6 +196,7 @@ extensions: []
154
196
  extra_rdoc_files: []
155
197
  files:
156
198
  - ".gitignore"
199
+ - ".rspec"
157
200
  - ".ruby-gemset"
158
201
  - ".ruby-version"
159
202
  - Gemfile
@@ -193,6 +236,14 @@ files:
193
236
  - lib/asaas/entity/notification.rb
194
237
  - lib/asaas/entity/payment.rb
195
238
  - lib/asaas/entity/subscription.rb
239
+ - lib/asaas/models/customer.rb
240
+ - lib/asaas/models/discount.rb
241
+ - lib/asaas/models/fine.rb
242
+ - lib/asaas/models/interest.rb
243
+ - lib/asaas/models/model.rb
244
+ - lib/asaas/models/payment.rb
245
+ - lib/asaas/models/webhook.rb
246
+ - lib/asaas/types.rb
196
247
  - lib/asaas/version.rb
197
248
  homepage: http://github.com/marcosgugs/asaas-ruby
198
249
  licenses: []