zoop 0.1.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 42c83c5481a3fb98de09d9c647a03498ad2e519f
4
+ data.tar.gz: 29e96491cfa027b6c200052f653f71b67fd2f562
5
+ SHA512:
6
+ metadata.gz: 005cb5236b80825602e80b57766c4533d2d9850e5f60e0e15af16db91b8a94c8388ffa5d73ab257d9d1dbc7760460c73c755ba44312fd67b53abcbc97a083df3
7
+ data.tar.gz: f917e3867a804791aa68c7e45e55fd3386101b8232fc6a8ff2c7163634b4dac779f5042d8e5aa9a28919c7a1ffe6251233c3137ea706106c46224e11da5cff95
data/.gitignore ADDED
@@ -0,0 +1,13 @@
1
+ *.gem
2
+ /.bundle/
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ Gemfile.lock
12
+
13
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.2
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at rodrigo.mgst@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in zoop.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Rodrigo Mageste
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Zoop
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/zoop`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'zoop'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install zoop
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/zoop. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Zoop project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/zoop/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'pry'
5
+
6
+ require_relative '../lib/zoop'
7
+ require_relative '../spec/spec_helper'
8
+
9
+ Class.new.extend(ZoopHelper).setup_zoop
10
+
11
+ Pry.start
@@ -0,0 +1,21 @@
1
+ class Object
2
+ def blank?
3
+ respond_to?(:empty?) ? !!empty? : !self
4
+ end
5
+
6
+ def present?
7
+ !blank?
8
+ end
9
+ end
10
+
11
+ class String
12
+ def convert_to_cents
13
+ (self.to_f * 100).to_i
14
+ end
15
+ end
16
+
17
+ class Hash
18
+ def deep_compact
19
+ delete_if {|k,v| v.deep_compact if v.is_a?(Hash); v.nil?}
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ module Zoop
2
+ class ZoopError < StandardError
3
+ end
4
+
5
+ class ConnectionError < ZoopError
6
+ attr_reader :error
7
+
8
+ def initialize(error)
9
+ @error = error
10
+ super error.message
11
+ end
12
+ end
13
+
14
+ class RequestError < ZoopError
15
+ end
16
+
17
+ class ResponseError < ZoopError
18
+ attr_reader :request_params, :error
19
+
20
+ def initialize(request_params, error)
21
+ @request_params, @error = request_params, error
22
+ super @error
23
+ end
24
+ end
25
+
26
+ class NotFound < ResponseError
27
+ attr_reader :response
28
+ def initialize(response, request_params, error)
29
+ @response = response
30
+ super request_params, error
31
+ end
32
+ end
33
+
34
+ end
data/lib/zoop/model.rb ADDED
@@ -0,0 +1,55 @@
1
+ module Zoop
2
+ class Model < ZoopObject
3
+
4
+ def create
5
+ update_model Zoop::Request.post(@custom_url || self.class.url, params: to_hash).run
6
+ self
7
+ end
8
+
9
+ def update(params={})
10
+ update_model Zoop::Request.put(@custom_url || url, params: params).run
11
+ self
12
+ end
13
+
14
+ def save
15
+ update_model Zoop::Request.put(@custom_url || url, params: unsaved_attributes).run
16
+ self
17
+ end
18
+
19
+ def destroy
20
+ update_model Zoop::Request.delete(url).run
21
+ self
22
+ end
23
+
24
+ def url(*params)
25
+ raise RequestError.new('Invalid ID') unless id.present?
26
+ self.class.url CGI.escape(id.to_s), *params
27
+ end
28
+
29
+ class << self
30
+
31
+ def create(*args, &block)
32
+ self.new(*args, &block).create
33
+ end
34
+
35
+ def find_by_id(id)
36
+ raise RequestError.new('Invalid ID') unless id.present?
37
+ Zoop::Request.get(url id).call
38
+ end
39
+ alias :find :find_by_id
40
+
41
+ def url(*params)
42
+ ["/#{ CGI.escape underscored_class_name }s", *params].join '/'
43
+ end
44
+
45
+ def class_name
46
+ self.name.split('::').last
47
+ end
48
+
49
+ def underscored_class_name
50
+ class_name.gsub(/[a-z0-9][A-Z]/){|s| "#{s[0]}_#{s[1]}"}.downcase
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,40 @@
1
+ module Zoop
2
+ class NestedModel < Model
3
+
4
+ def create
5
+ @custom_url = self.class.url(parent_id)
6
+ super
7
+ end
8
+
9
+ def url(*params)
10
+ raise RequestError.new('Invalid ID') unless id.present?
11
+ self.class.url parent_id, CGI.escape(id.to_s), *params
12
+ end
13
+
14
+ class << self
15
+
16
+ def parent_resource_name
17
+ raise NotImplementedError
18
+ end
19
+
20
+ def find_by_id(parent_id:, id:)
21
+ raise RequestError.new('Invalid ID') unless id.present?
22
+ raise RequestError.new('Invalid parent ID') unless parent_id.present?
23
+
24
+ Zoop::Request.get(url parent_id, id).call
25
+ end
26
+ alias :find :find_by_id
27
+
28
+ def url(parent_id, *params)
29
+ raise RequestError.new('Invalid parent ID') unless parent_id.present?
30
+ ["/#{parent_resource_name}", parent_id, "#{ CGI.escape underscored_class_name }s", *params].join '/'
31
+ end
32
+ end
33
+
34
+ protected
35
+
36
+ def parent_id
37
+ raise NotImplementedError
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,137 @@
1
+ module Zoop
2
+ class ZoopObject
3
+ attr_reader :attributes
4
+
5
+ RESOURCES = Dir[File.expand_path('../resources/*.rb', __FILE__)].map do |path|
6
+ File.basename(path, '.rb').to_sym
7
+ end
8
+
9
+ def initialize(response = {})
10
+ @attributes = Hash.new
11
+ @unsaved_attributes = Set.new
12
+ update_model response
13
+ end
14
+
15
+ def []=(key,value)
16
+ @attributes[key] = value
17
+ @unsaved_attributes.add key
18
+ end
19
+
20
+ def empty?
21
+ @attributes.empty?
22
+ end
23
+
24
+ def ==(other)
25
+ self.class == other.class && id == other.id
26
+ end
27
+
28
+ def unsaved_attributes
29
+ Hash[@unsaved_attributes.map do |key|
30
+ [ key, to_hash_value(self[key], :unsaved_attributes) ]
31
+ end]
32
+ end
33
+
34
+ def to_hash
35
+ Hash[@attributes.map do |key, value|
36
+ [ key, to_hash_value(value, :to_hash) ]
37
+ end]
38
+ end
39
+
40
+ def respond_to?(name, include_all = false)
41
+ return true if name.to_s.end_with? '='
42
+
43
+ @attributes.has_key?(name.to_s) || super
44
+ end
45
+
46
+ def to_s
47
+ attributes_str = ''
48
+ (attributes.keys - ['id', 'object']).sort.each do |key|
49
+ attributes_str += " \033[1;33m#{key}:\033[0m#{self[key].inspect}" unless self[key].nil?
50
+ end
51
+ "\033[1;31m#<#{self.class.name}:\033[0;32m#{id}#{attributes_str}\033[0m\033[0m\033[1;31m>\033[0m"
52
+ end
53
+ alias :inspect :to_s
54
+
55
+ protected
56
+
57
+ def update_model(attributes)
58
+ removed_attributes = @attributes.keys - attributes.keys
59
+
60
+ removed_attributes.each do |key|
61
+ @attributes.delete key
62
+ end
63
+
64
+ attributes.each do |key, value|
65
+ key = key.to_s
66
+
67
+ @attributes[key] = ZoopObject.convert(value)
68
+ @unsaved_attributes.delete key
69
+ end
70
+ end
71
+
72
+ def to_hash_value(value, type)
73
+ case value
74
+ when ZoopObject
75
+ value.send type
76
+ when Array
77
+ value.map do |v|
78
+ to_hash_value v, type
79
+ end
80
+ else
81
+ value
82
+ end
83
+ end
84
+
85
+ def method_missing(name, *args, &block)
86
+ name = name.to_s
87
+
88
+ unless block_given?
89
+ if name.end_with?('=') && args.size == 1
90
+ attribute_name = name[0...-1]
91
+ return self[attribute_name] = args[0]
92
+ end
93
+
94
+ if args.size == 0
95
+ return self[name] || self[name.to_sym]
96
+ end
97
+ end
98
+
99
+ if attributes.respond_to? name
100
+ return attributes.public_send name, *args, &block
101
+ end
102
+
103
+ super name, *args, &block
104
+ end
105
+
106
+ class << self
107
+
108
+ def convert(response)
109
+ case response
110
+ when Array
111
+ response.map{ |i| convert i }
112
+ when Hash
113
+ resource_class_for(response['resource']).new(response)
114
+ else
115
+ response
116
+ end
117
+ end
118
+
119
+ protected
120
+
121
+ def resource_class_for(resource_name)
122
+ return Zoop::ZoopObject if resource_name.nil?
123
+
124
+ if RESOURCES.include? resource_name.to_sym
125
+ Object.const_get "Zoop::#{capitalize_name resource_name}"
126
+ else
127
+ Zoop::ZoopObject
128
+ end
129
+ end
130
+
131
+ def capitalize_name(name)
132
+ name.gsub(/(\A\w|\_\w)/){ |str| str.gsub('_', '').upcase }
133
+ end
134
+
135
+ end
136
+ end
137
+ end
@@ -0,0 +1,21 @@
1
+ module Zoop
2
+ class PaymentMethodCommon < Model
3
+
4
+ def create
5
+ return super if self.token.present?
6
+
7
+ token = Zoop::Token.create(to_hash)
8
+ token.payment_method.token = token.id
9
+ token.payment_method
10
+ end
11
+
12
+ def associate(customer_id)
13
+ raise RequestError.new('Invalid Token ID') unless token.present?
14
+ self.class.associate(customer: customer_id.to_s, token: token.to_s)
15
+ end
16
+
17
+ class << self
18
+ alias :associate :create
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,102 @@
1
+ require 'uri'
2
+ require 'rest_client'
3
+ require 'multi_json'
4
+
5
+ module Zoop
6
+ class Request
7
+ attr_accessor :path, :method, :parameters, :headers, :query, :full_api_url
8
+
9
+ DEFAULT_HEADERS = {
10
+ 'Content-Type' => 'application/json',
11
+ 'Accept' => 'application/json',
12
+ 'User-Agent' => "zoop-ruby/#{Zoop::VERSION}"
13
+ }
14
+
15
+ def initialize(path, method, options={})
16
+ raise Zoop::RequestError, 'You need to configure a Zoop.marketplace_id (ZOOP_MARKETPLACE_ID), Zoop.user_auth (ZOOP_USER_AUTH), Zoop.password_auth (ZOOP_PASSWORD_AUTH) before performing requests.' unless Zoop.marketplace_id && Zoop.user_auth && Zoop.password_auth
17
+
18
+ @path = path
19
+ @method = method
20
+ @full_api_url = options[:full_api_url]
21
+ @query = options[:query] || Hash.new
22
+ @parameters = options[:params] || Hash.new
23
+ @headers = options[:headers] || Hash.new
24
+ end
25
+
26
+ def run
27
+ response = RestClient::Request.execute request_params
28
+ MultiJson.decode response.body
29
+ rescue RestClient::Exception => error
30
+ begin
31
+ parsed_error = MultiJson.decode error.http_body
32
+
33
+ if error.is_a? RestClient::ResourceNotFound
34
+ raise Zoop::NotFound.new(parsed_error, request_params, error)
35
+ else
36
+ raise Zoop::ResponseError.new(request_params, parsed_error)
37
+ end
38
+ rescue MultiJson::ParseError
39
+ raise Zoop::ResponseError.new(request_params, error.http_body)
40
+ end
41
+ rescue MultiJson::ParseError
42
+ raise Zoop::ResponseError.new(request_params, response.body)
43
+ rescue SocketError
44
+ raise Zoop::ConnectionError.new $!
45
+ rescue RestClient::ServerBrokeConnection
46
+ raise Zoop::ConnectionError.new $!
47
+ end
48
+
49
+ def call
50
+ ZoopObject.convert run
51
+ end
52
+
53
+ def self.get(url, options={})
54
+ self.new url, 'GET', options
55
+ end
56
+
57
+ def self.post(url, options={})
58
+ self.new url, 'POST', options
59
+ end
60
+
61
+ def self.put(url, options={})
62
+ self.new url, 'PUT', options
63
+ end
64
+
65
+ def self.delete(url, options={})
66
+ self.new url, 'DELETE', options
67
+ end
68
+
69
+ protected
70
+
71
+ def request_params
72
+ {
73
+ method: method,
74
+ user: Zoop.user_auth,
75
+ password: Zoop.password_auth,
76
+ url: full_api_url || full_api_url_with_marketplace,
77
+ payload: formated_parameters,
78
+ open_timeout: Zoop.open_timeout,
79
+ timeout: Zoop.timeout,
80
+ headers: DEFAULT_HEADERS.merge(headers)
81
+ }.deep_compact
82
+ end
83
+
84
+ def full_api_url_with_marketplace
85
+ url = Zoop.api_endpoint + "/marketplaces/#{Zoop.marketplace_id}" + path
86
+
87
+ if query.present?
88
+ url += '?' + URI.encode_www_form(query)
89
+ end
90
+
91
+ url
92
+ end
93
+
94
+ def formated_parameters
95
+ if parameters.include?(:file)
96
+ parameters
97
+ elsif parameters.present?
98
+ MultiJson.encode(parameters)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,4 @@
1
+ module Zoop
2
+ class BankAccount < Zoop::PaymentMethodCommon
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Zoop
2
+ class Buyer < Zoop::Model
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Zoop
2
+ class Card < Zoop::PaymentMethodCommon
3
+ end
4
+ end
@@ -0,0 +1,44 @@
1
+ module Zoop
2
+ class Seller < Zoop::Model
3
+
4
+ def create
5
+ @custom_url = self.class.url(mount_url)
6
+ super
7
+ end
8
+
9
+ def update(params={})
10
+ raise RequestError.new('Invalid ID') unless id.present?
11
+ @custom_url = self.class.url(mount_url, CGI.escape(id.to_s))
12
+ super
13
+ end
14
+
15
+ def save
16
+ raise RequestError.new('Invalid ID') unless id.present?
17
+ @custom_url = self.class.url(mount_url, CGI.escape(id.to_s))
18
+ super
19
+ end
20
+
21
+ def receiving_policy
22
+ Zoop::Request.get(url 'receiving_policy').call
23
+ end
24
+
25
+ def update_receiving_policy(params={})
26
+ Zoop::Request.post(url('receiving_policy'), params: params).call
27
+ end
28
+
29
+ def documents
30
+ Zoop::Request.get( url 'documents' ).call
31
+ end
32
+
33
+ def upload_documents(params={})
34
+ Zoop::Request.post(url('documents'), params: params).call
35
+ end
36
+
37
+ private
38
+
39
+ def mount_url
40
+ self.type == 'business' ? 'businesses' : 'individuals'
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,18 @@
1
+ module Zoop
2
+ class SplitRule < Zoop::NestedModel
3
+
4
+ class << self
5
+
6
+ def parent_resource_name
7
+ 'transactions'
8
+ end
9
+ end
10
+
11
+ protected
12
+
13
+ def parent_id
14
+ self.transaction
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,34 @@
1
+ module Zoop
2
+ class Token < Zoop::Model
3
+
4
+ def create
5
+ @custom_url = self.class.url(self.card_number.present?)
6
+ super
7
+ end
8
+
9
+ def destroy
10
+ raise NotImplementedError
11
+ end
12
+
13
+ def associate(customer_id)
14
+ raise RequestError.new('Invalid Token ID') unless id.present?
15
+ payment_method.class.associate(customer: customer_id.to_s, token: id.to_s)
16
+ end
17
+
18
+ def payment_method
19
+ self.card || self.bank_account
20
+ end
21
+
22
+ class << self
23
+
24
+ def url(*params)
25
+ case params.first
26
+ when TrueClass then '/cards/tokens'
27
+ when FalseClass then '/bank_accounts/tokens'
28
+ else super(*params)
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,37 @@
1
+ module Zoop
2
+ class Transaction < Zoop::Model
3
+ alias :charge :create
4
+
5
+ def initialize(response = {})
6
+ super(response)
7
+
8
+ self.currency ||= 'BRL'
9
+ self.payment_type ||= 'credit'
10
+ self.capture ||= true
11
+ end
12
+
13
+ def capture!
14
+ params = { amount: amount.convert_to_cents, on_behalf_of: on_behalf_of }
15
+ update_model Zoop::Request.post(url('capture'), params: params).run
16
+ self
17
+ end
18
+
19
+ def refund
20
+ params = { amount: amount.convert_to_cents, on_behalf_of: on_behalf_of }
21
+ update_model Zoop::Request.post(url('void'), params: params).run
22
+ self
23
+ end
24
+
25
+ def receivables
26
+ Zoop::Request.get( url 'receivables' ).call
27
+ end
28
+
29
+ def destroy
30
+ raise NotImplementedError
31
+ end
32
+
33
+ class << self
34
+ alias :charge :create
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Zoop
2
+ VERSION = '0.1.0'
3
+ end
data/lib/zoop.rb ADDED
@@ -0,0 +1,27 @@
1
+ require 'set'
2
+
3
+ require_relative 'zoop/version'
4
+ require_relative 'zoop/core_ext'
5
+ require_relative 'zoop/object'
6
+ require_relative 'zoop/model'
7
+ require_relative 'zoop/nested_model'
8
+ require_relative 'zoop/errors'
9
+ require_relative 'zoop/request'
10
+ require_relative 'zoop/payment_method_common'
11
+
12
+ Dir[File.expand_path('../zoop/resources/*.rb', __FILE__)].map do |path|
13
+ require path
14
+ end
15
+
16
+ module Zoop
17
+ class << self
18
+ attr_accessor :api_endpoint, :open_timeout, :timeout, :marketplace_id, :user_auth, :password_auth
19
+ end
20
+
21
+ self.api_endpoint = 'https://api.zoop.ws/v1'
22
+ self.open_timeout = 30
23
+ self.timeout = 90
24
+ self.marketplace_id = ENV['ZOOP_MARKETPLACE_ID']
25
+ self.user_auth = ENV['ZOOP_USER_AUTH']
26
+ self.password_auth = ENV['ZOOP_PASSWORD_AUTH']
27
+ end
data/zoop.gemspec ADDED
@@ -0,0 +1,32 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'zoop/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'zoop'
7
+ spec.version = Zoop::VERSION
8
+ spec.authors = ['Rodrigo Mageste']
9
+ spec.email = ['rodrigo.mgst@gmail.com']
10
+
11
+ spec.summary = %q{Zoop's ruby gem}
12
+ spec.description = %q{Allows integration with Zoop}
13
+ spec.homepage = 'https://zoop.co/'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'bin'
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.16'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec', '~> 3.0'
26
+ spec.add_development_dependency 'factory_bot'
27
+ spec.add_development_dependency 'cpf_faker'
28
+ spec.add_development_dependency 'pry'
29
+
30
+ spec.add_dependency 'rest-client'
31
+ spec.add_dependency 'multi_json'
32
+ end
metadata ADDED
@@ -0,0 +1,183 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: zoop
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Rodrigo Mageste
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: factory_bot
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cpf_faker
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rest-client
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: multi_json
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Allows integration with Zoop
126
+ email:
127
+ - rodrigo.mgst@gmail.com
128
+ executables:
129
+ - console
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - ".gitignore"
134
+ - ".rspec"
135
+ - ".travis.yml"
136
+ - CODE_OF_CONDUCT.md
137
+ - Gemfile
138
+ - LICENSE.txt
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - lib/zoop.rb
143
+ - lib/zoop/core_ext.rb
144
+ - lib/zoop/errors.rb
145
+ - lib/zoop/model.rb
146
+ - lib/zoop/nested_model.rb
147
+ - lib/zoop/object.rb
148
+ - lib/zoop/payment_method_common.rb
149
+ - lib/zoop/request.rb
150
+ - lib/zoop/resources/bank_account.rb
151
+ - lib/zoop/resources/buyer.rb
152
+ - lib/zoop/resources/card.rb
153
+ - lib/zoop/resources/seller.rb
154
+ - lib/zoop/resources/split_rule.rb
155
+ - lib/zoop/resources/token.rb
156
+ - lib/zoop/resources/transaction.rb
157
+ - lib/zoop/version.rb
158
+ - zoop.gemspec
159
+ homepage: https://zoop.co/
160
+ licenses:
161
+ - MIT
162
+ metadata: {}
163
+ post_install_message:
164
+ rdoc_options: []
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: '0'
172
+ required_rubygems_version: !ruby/object:Gem::Requirement
173
+ requirements:
174
+ - - ">="
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ requirements: []
178
+ rubyforge_project:
179
+ rubygems_version: 2.6.13
180
+ signing_key:
181
+ specification_version: 4
182
+ summary: Zoop's ruby gem
183
+ test_files: []