moyasar 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 48eb372c6959242b42c3a8f5da6269d44831aa50
4
+ data.tar.gz: 1199cd8a6a5113994b56902fa30dbc8bca46e5a1
5
+ SHA512:
6
+ metadata.gz: 4418544cd0dc55a9bff2cfdf959df8c6f2e6b31b2360532c63b2dd568c2505e41052331f3ae3ea0176ceac734efc0090a812bd2304ea88ae0260af6742dbdc6b
7
+ data.tar.gz: da4e0433ca544e8772218f065f18368a9a5e57be02bc9f013f3e12b36a47406086a34f7e9a126aa927d6b36c5f13911deb276398c9772afb6d619d391161070d
data/.gitignore ADDED
@@ -0,0 +1,36 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ ## Specific to RubyMotion:
14
+ .dat*
15
+ .repl_history
16
+ build/
17
+
18
+ ## Documentation cache and generated files:
19
+ /.yardoc/
20
+ /_yardoc/
21
+ /doc/
22
+ /rdoc/
23
+
24
+ ## Environment normalization:
25
+ /.bundle/
26
+ /vendor/bundle
27
+ /lib/bundler/man/
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ # Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
34
+
35
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
36
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in moyasar.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'minitest-reporters'
8
+ gem 'guard' # NOTE: this is necessary in newer versions
9
+ gem 'guard-minitest'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,70 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ moyasar (0.3.1)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ builder (3.2.2)
11
+ coderay (1.1.1)
12
+ ffi (1.9.14)
13
+ formatador (0.2.5)
14
+ guard (2.14.0)
15
+ formatador (>= 0.2.4)
16
+ listen (>= 2.7, < 4.0)
17
+ lumberjack (~> 1.0)
18
+ nenv (~> 0.1)
19
+ notiffany (~> 0.0)
20
+ pry (>= 0.9.12)
21
+ shellany (~> 0.0)
22
+ thor (>= 0.18.1)
23
+ guard-compat (1.2.1)
24
+ guard-minitest (2.4.6)
25
+ guard-compat (~> 1.2)
26
+ minitest (>= 3.0)
27
+ listen (3.1.5)
28
+ rb-fsevent (~> 0.9, >= 0.9.4)
29
+ rb-inotify (~> 0.9, >= 0.9.7)
30
+ ruby_dep (~> 1.2)
31
+ lumberjack (1.0.10)
32
+ method_source (0.8.2)
33
+ minitest (5.9.0)
34
+ minitest-reporters (1.1.11)
35
+ ansi
36
+ builder
37
+ minitest (>= 5.0)
38
+ ruby-progressbar
39
+ nenv (0.3.0)
40
+ notiffany (0.1.1)
41
+ nenv (~> 0.1)
42
+ shellany (~> 0.0)
43
+ pry (0.10.4)
44
+ coderay (~> 1.1.0)
45
+ method_source (~> 0.8.1)
46
+ slop (~> 3.4)
47
+ rake (11.2.2)
48
+ rb-fsevent (0.9.7)
49
+ rb-inotify (0.9.7)
50
+ ffi (>= 0.5.0)
51
+ ruby-progressbar (1.8.1)
52
+ ruby_dep (1.4.0)
53
+ shellany (0.0.1)
54
+ slop (3.6.0)
55
+ thor (0.19.1)
56
+
57
+ PLATFORMS
58
+ ruby
59
+
60
+ DEPENDENCIES
61
+ bundler
62
+ guard
63
+ guard-minitest
64
+ minitest
65
+ minitest-reporters
66
+ moyasar!
67
+ rake
68
+
69
+ BUNDLED WITH
70
+ 1.12.5
data/Guardfile ADDED
@@ -0,0 +1,45 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ guard :minitest do
19
+ # with Minitest::Unit
20
+ watch(%r{^test/(.*)\/?(.*)_test\.rb$})
21
+ watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}#{m[2]}_test.rb" }
22
+ watch(%r{^test/test_helper\.rb$}) { 'test' }
23
+ watch(%r{^lib/moyasar\.rb$})
24
+ watch(%r{^lib/(.*)\/?(.*)\.rb$})
25
+ watch(%r{^lib/moyasar/actions\/?(.*)\.rb$})
26
+
27
+ # with Minitest::Spec
28
+ # watch(%r{^spec/(.*)_spec\.rb$})
29
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
30
+ # watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
31
+
32
+ # Rails 4
33
+ # watch(%r{^app/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
34
+ # watch(%r{^app/controllers/application_controller\.rb$}) { 'test/controllers' }
35
+ # watch(%r{^app/controllers/(.+)_controller\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
36
+ # watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
37
+ # watch(%r{^lib/(.+)\.rb$}) { |m| "test/lib/#{m[1]}_test.rb" }
38
+ # watch(%r{^test/.+_test\.rb$})
39
+ # watch(%r{^test/test_helper\.rb$}) { 'test' }
40
+
41
+ # Rails < 4
42
+ # watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
43
+ # watch(%r{^app/helpers/(.*)\.rb$}) { |m| "test/helpers/#{m[1]}_test.rb" }
44
+ # watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
45
+ end
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Moyasar
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,59 @@
1
+ # moyasar-ruby
2
+
3
+ Moyasar Ruby language wrapper
4
+
5
+ ## Documentation
6
+
7
+ See the [Ruby API docs](https://moyasar.com/docs/api/?ruby).
8
+
9
+ ### Requirements
10
+
11
+ * Ruby 2.0 or above.
12
+
13
+ ## Installation
14
+
15
+ Add this line to your application's Gemfile:
16
+
17
+ ```ruby
18
+ gem 'moyasar'
19
+ ```
20
+
21
+ And then execute:
22
+
23
+ $ bundle
24
+
25
+ Or install it yourself as:
26
+
27
+ $ gem install moyasar
28
+
29
+ ## Usage
30
+
31
+ ``` ruby
32
+ require "moyasar"
33
+ Moyasar.api_key = "sk_test_..."
34
+
35
+ # list payments
36
+ Moyasar::Payment.list()
37
+
38
+ # fetch single charge
39
+ Moyasar::Payment.fetch("760878ec-d1d3-5f72-9056-191683f55872")
40
+
41
+ # create an invoice
42
+ Moyasar::Invoice.create({amount: 2500, description: "Monthly subscription"})
43
+ ```
44
+
45
+ ## Development
46
+
47
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
48
+
49
+ 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).
50
+
51
+ ## Contributing
52
+
53
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/moyasar. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
54
+
55
+
56
+ ## License
57
+
58
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
59
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.libs << 'lib'
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "moyasar"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,34 @@
1
+ module Moyasar
2
+ module Actions
3
+ module Construct
4
+
5
+ def self.included(klass)
6
+ klass.extend ClassMethods
7
+ klass.send :include, InstanceMethods
8
+ klass.send :prepend, Initializer
9
+ end
10
+
11
+ module ClassMethods
12
+ end
13
+
14
+ module InstanceMethods
15
+
16
+ def construct(attrs = {})
17
+ attrs.each do |key, value|
18
+ self.instance_variable_set("@#{key}".to_sym, value)
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ module Initializer
25
+ def initialize(attrs = {})
26
+ # puts "construct ...#{self} #{attrs}"
27
+ construct(attrs)
28
+ super()
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,23 @@
1
+ module Moyasar
2
+ module Actions
3
+ module Create
4
+
5
+ def self.included(klass)
6
+ klass.extend ClassMethods
7
+ klass.send :include, InstanceMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ def create(attrs = {})
12
+ response = request(:post, create_url, params: attrs)
13
+
14
+ new(response.body)
15
+ end
16
+ end
17
+
18
+ module InstanceMethods
19
+ end
20
+
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ module Moyasar
2
+ module Actions
3
+ module Fetch
4
+
5
+ def self.included(klass)
6
+ klass.extend ClassMethods
7
+ klass.send :include, InstanceMethods
8
+ end
9
+
10
+ module ClassMethods
11
+
12
+ def fetch(id)
13
+ response = request(:get, find_url(id))
14
+ new(response.body)
15
+ end
16
+ alias find fetch
17
+
18
+ end
19
+
20
+ module InstanceMethods
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,24 @@
1
+ module Moyasar
2
+ module Actions
3
+ module List
4
+
5
+ def self.included(klass)
6
+ klass.extend ClassMethods
7
+ klass.send :include, InstanceMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ # TODO should accept pagination and query options
12
+ def list(attrs = {})
13
+ response = request(:get, list_url, params: attrs)
14
+ response.body[resource_name].map { |resource| new(resource) }
15
+ end
16
+ alias all list
17
+ end
18
+
19
+ module InstanceMethods
20
+ end
21
+
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,15 @@
1
+ module Moyasar
2
+ module Actions
3
+ module Request
4
+
5
+ def self.included(klass)
6
+ klass.extend Request
7
+ end
8
+
9
+ def request(method, url, params: {}, headers: {})
10
+ Moyasar.request(method, url, params: params, headers: headers)
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,28 @@
1
+ module Moyasar
2
+ module Actions
3
+ module Update
4
+
5
+ def self.included(klass)
6
+ klass.extend ClassMethods
7
+ klass.send :include, InstanceMethods
8
+ end
9
+
10
+ module ClassMethods
11
+ end
12
+
13
+ module InstanceMethods
14
+ def update(attrs = {})
15
+ response = request(:put, update_url(id), params: attrs)
16
+
17
+ if response.code.to_i == 200
18
+ true
19
+ else
20
+ false
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,4 @@
1
+ module Moyasar
2
+ class AccountInactiveError < MoyasarError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Moyasar
2
+ class APIConnectionError < MoyasarError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Moyasar
2
+ class APIError < MoyasarError
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Moyasar
2
+ class AuthenticationError < MoyasarError
3
+ end
4
+ end
@@ -0,0 +1,10 @@
1
+ module Moyasar
2
+ class InvalidRequestError < MoyasarError
3
+ attr_reader :errors
4
+
5
+ def initialize(attrs = {})
6
+ @errors = attrs['errors']
7
+ super
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module Moyasar
2
+ class MoyasarError < StandardError
3
+ attr_reader :type, :http_code
4
+
5
+ def initialize(attrs = {})
6
+ @type = attrs['type']
7
+ @http_code = attrs['code']
8
+ super(attrs['message'])
9
+ end
10
+
11
+ def to_s
12
+ status_string = @http_code.nil? ? "" : "(Status #{@http_code}) "
13
+ "#{status_string}#{@message}"
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ module Moyasar
2
+ class RateLimitError < MoyasarError
3
+ end
4
+ end
@@ -0,0 +1,54 @@
1
+ module Moyasar
2
+ class HTTPClient
3
+ METHOD_CLASS = {
4
+ head: Net::HTTP::Head,
5
+ get: Net::HTTP::Get,
6
+ post: Net::HTTP::Post,
7
+ put: Net::HTTP::Put,
8
+ delete: Net::HTTP::Delete
9
+ }.freeze
10
+
11
+ DEFAULT_HEADERS = {
12
+ 'Content-Type' => 'application/json'
13
+ }.freeze
14
+
15
+ def initialize(endpoint)
16
+ uri = URI.parse(endpoint)
17
+ @http = Net::HTTP.new(uri.host, uri.port)
18
+ @http.use_ssl = true
19
+ end
20
+
21
+ def request(method, path, key = nil, params = {}, headers = {})
22
+ case method
23
+ when :get
24
+ full_path = encode_path_params(path, params)
25
+ request = METHOD_CLASS[method.to_sym].new(full_path, DEFAULT_HEADERS)
26
+ else
27
+ request = METHOD_CLASS[method.to_sym].new(path, DEFAULT_HEADERS)
28
+ # post_data = URI.encode_www_form(params)
29
+ request.body = params.to_json
30
+ end
31
+
32
+ request.basic_auth(key, '') unless key.nil?
33
+
34
+ @http.request(request)
35
+ end
36
+
37
+ def request_json(method, path, key = nil, params = {}, headers = {})
38
+ response = request(method, path, key, params, headers)
39
+ body = JSON.parse(response.body)
40
+
41
+ OpenStruct.new(code: response.code.to_i, body: body)
42
+ rescue JSON::ParserError
43
+ response
44
+ end
45
+
46
+ private
47
+
48
+ def encode_path_params(path, params)
49
+ encoded = URI.encode_www_form(params)
50
+ [path, encoded].join('?')
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,7 @@
1
+ module Moyasar
2
+ class Invoice < Resource
3
+ attr_reader :id, :status, :created_at, :modified_at
4
+ attr_accessor :description, :amount, :currency
5
+
6
+ end
7
+ end
@@ -0,0 +1,26 @@
1
+ module Moyasar
2
+ class Payment < Resource
3
+ attr_reader :id, :status, :amount, :currency, :source, :created_at, :modified_at
4
+ attr_accessor :description
5
+
6
+ def initialize(attrs = {})
7
+ source = attrs.delete('source')
8
+ type = source.delete('type')
9
+ @source = Moyasar::Source.build(type, source)
10
+
11
+ super
12
+ end
13
+
14
+ # TODO == should work between payments
15
+
16
+ class << self
17
+
18
+ def create(source:, amount:, currency: 'SAR', description: nil)
19
+ params = {amount: amount, currency: currency, description: description, source: source}
20
+ super(params)
21
+ end
22
+
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,50 @@
1
+ module Moyasar
2
+ class Resource
3
+ include Moyasar::Actions::Request
4
+ include Moyasar::Actions::Construct
5
+ include Moyasar::Actions::Create
6
+ include Moyasar::Actions::List
7
+ include Moyasar::Actions::Fetch
8
+ include Moyasar::Actions::Update
9
+
10
+ class << self
11
+
12
+ def class_name
13
+ name.split('::')[-1]
14
+ end
15
+
16
+ def resource_name
17
+ "#{class_name.downcase}s"
18
+ end
19
+
20
+ def resource_url
21
+ if self == Resource
22
+ raise NotImplementedError.new('Resource is an abstract class. You should perform actions on its subclasses (Payment, Invoice, etc.)')
23
+ end
24
+ "/#{Moyasar.api_version}/#{CGI.escape(resource_name)}"
25
+ end
26
+
27
+ private
28
+
29
+ def create_url
30
+ resource_url
31
+ end
32
+
33
+ def list_url
34
+ create_url
35
+ end
36
+
37
+ def find_url(id)
38
+ "#{resource_url}/#{id}"
39
+ end
40
+
41
+ end
42
+
43
+ private
44
+
45
+ def update_url(id)
46
+ "#{self.class.resource_url}/#{id}"
47
+ end
48
+
49
+ end
50
+ end
@@ -0,0 +1,18 @@
1
+ module Moyasar
2
+ class Source
3
+ include Moyasar::Actions::Construct
4
+
5
+ class << self
6
+ def build(type, attrs = {})
7
+ sources = {
8
+ 'sadad' => Sadad,
9
+ 'creditcard' => CreditCard
10
+ }
11
+
12
+ sources[type].new(attrs)
13
+ end
14
+ # private new
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ module Moyasar
2
+ class CreditCard < Source
3
+ attr_reader :company, :name, :number, :message
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Moyasar
2
+ class Sadad < Source
3
+ attr_reader :username, :error_code, :message, :transaction_url, :transaction_id
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module Moyasar
2
+ VERSION = '0.3.1'
3
+ end
data/lib/moyasar.rb ADDED
@@ -0,0 +1,68 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'json'
4
+ require 'ostruct'
5
+
6
+ require 'moyasar/version'
7
+ require 'moyasar/http_client'
8
+
9
+ require 'moyasar/actions/request'
10
+ require 'moyasar/actions/construct'
11
+ require 'moyasar/actions/create'
12
+ require 'moyasar/actions/list'
13
+ require 'moyasar/actions/fetch'
14
+ require 'moyasar/actions/update'
15
+
16
+ require 'moyasar/source'
17
+ require 'moyasar/resource'
18
+ require 'moyasar/payment'
19
+ require 'moyasar/invoice'
20
+
21
+ require 'moyasar/sources/sadad'
22
+ require 'moyasar/sources/credit_card'
23
+
24
+ require 'moyasar/errors/moyasar_error'
25
+ require 'moyasar/errors/authentication_error'
26
+ require 'moyasar/errors/invalid_request_error'
27
+ require 'moyasar/errors/account_inactive_error'
28
+ require 'moyasar/errors/rate_limit_error'
29
+ require 'moyasar/errors/api_connection_error'
30
+ require 'moyasar/errors/api_error'
31
+
32
+ module Moyasar
33
+ @api_base = 'https://apimig.moyasar.com'
34
+ @api_version = 'v1'
35
+
36
+ @client = Moyasar::HTTPClient.new(@api_base)
37
+
38
+ Errors = {
39
+ 'authentication_error' => Moyasar::AuthenticationError,
40
+ 'invalid_request_error' => Moyasar::InvalidRequestError,
41
+ 'account_inactive_error' => Moyasar::AccountInactiveError,
42
+ 'rate_limit_error' => Moyasar::RateLimitError,
43
+ 'api_connection_error' => Moyasar::APIConnectionError,
44
+ 'api_error' => Moyasar::APIError,
45
+ }.freeze
46
+
47
+ class << self
48
+ attr_accessor :api_key
49
+ attr_reader :api_base, :api_version
50
+
51
+ def request(method, url, key: nil, params: {}, headers: {})
52
+ unless key ||= @api_key
53
+ raise AuthenticationError.new('No API Key provided.')
54
+ end
55
+
56
+ # puts method, url, key
57
+ response = @client.request_json(method, url, key, params, headers)
58
+ case response.code
59
+ when 400..401
60
+ error_data = response.body.merge({'http_code' => response.code})
61
+ error = Errors[response.body['type']].new(error_data)
62
+ raise error
63
+ end
64
+ response
65
+ end
66
+
67
+ end
68
+ end
data/moyasar.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'moyasar/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'moyasar'
8
+ spec.version = Moyasar::VERSION
9
+ spec.authors = ['Abdulaziz AlShetwi']
10
+ spec.email = ['developers@moyasar.com']
11
+
12
+ spec.summary = %q{Ruby bindings for Moyasar Payment service}
13
+ spec.description = %q{Ruby bindings for Moyasar Payment service.}
14
+ spec.homepage = 'https://moyasar.com/docs/api'
15
+ spec.license = 'MIT'
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ # if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ # else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ # end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = 'exe'
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ['lib']
29
+
30
+ spec.add_development_dependency 'bundler' # , "~> 1.10"
31
+ spec.add_development_dependency 'rake' # , "~> 10.0"
32
+ spec.add_development_dependency 'minitest'
33
+
34
+ spec.required_ruby_version = '>= 2.0.0'
35
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: moyasar
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Abdulaziz AlShetwi
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-10-10 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Ruby bindings for Moyasar Payment service.
56
+ email:
57
+ - developers@moyasar.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - Gemfile
64
+ - Gemfile.lock
65
+ - Guardfile
66
+ - LICENSE
67
+ - README.md
68
+ - Rakefile
69
+ - bin/console
70
+ - bin/setup
71
+ - lib/moyasar.rb
72
+ - lib/moyasar/actions/construct.rb
73
+ - lib/moyasar/actions/create.rb
74
+ - lib/moyasar/actions/fetch.rb
75
+ - lib/moyasar/actions/list.rb
76
+ - lib/moyasar/actions/request.rb
77
+ - lib/moyasar/actions/update.rb
78
+ - lib/moyasar/errors/account_inactive_error.rb
79
+ - lib/moyasar/errors/api_connection_error.rb
80
+ - lib/moyasar/errors/api_error.rb
81
+ - lib/moyasar/errors/authentication_error.rb
82
+ - lib/moyasar/errors/invalid_request_error.rb
83
+ - lib/moyasar/errors/moyasar_error.rb
84
+ - lib/moyasar/errors/rate_limit_error.rb
85
+ - lib/moyasar/http_client.rb
86
+ - lib/moyasar/invoice.rb
87
+ - lib/moyasar/payment.rb
88
+ - lib/moyasar/resource.rb
89
+ - lib/moyasar/source.rb
90
+ - lib/moyasar/sources/credit_card.rb
91
+ - lib/moyasar/sources/sadad.rb
92
+ - lib/moyasar/version.rb
93
+ - moyasar.gemspec
94
+ homepage: https://moyasar.com/docs/api
95
+ licenses:
96
+ - MIT
97
+ metadata: {}
98
+ post_install_message:
99
+ rdoc_options: []
100
+ require_paths:
101
+ - lib
102
+ required_ruby_version: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 2.0.0
107
+ required_rubygems_version: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: '0'
112
+ requirements: []
113
+ rubyforge_project:
114
+ rubygems_version: 2.5.1
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: Ruby bindings for Moyasar Payment service
118
+ test_files: []