paymium_api 0.0.5 → 0.0.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: cd2cf816dc21ba6384b3896f012afd21b44d5172
4
- data.tar.gz: 1027f7c902ab4d9e297fe6f642d037e978bfc454
2
+ SHA256:
3
+ metadata.gz: 6c025a22cfba6934c4dadaa91a262353dcf6657a9f47ac1f410f235397f46ecd
4
+ data.tar.gz: 7ace61b9ae588bbfdfae827a0d17e352cf746c3036fe7777b26ce3cbe53e6d79
5
5
  SHA512:
6
- metadata.gz: 362f5d7c0e8564292d75a6639620ca126733709f1244bfe80805bff98b3c5e0fb422ea901abcada0c8edb672719282658a29c4e125e56af8130aac771f20876c
7
- data.tar.gz: 4f172ef1639dfc76b048da0fdf8e16aaed4a6176b75f3f2dbe8859488582d2576e09c3b8d0ed95558cc3e1ba6ca85f06f224573d652e12447793ccb96a1a4c25
6
+ metadata.gz: aa9c2e2175d200127f5c041e1df275e6fdf220c5c944bb85af94d9ef3905ea970fd0381e9d097c8f3dfabdd193e4137bb720e3f497b68e82d3942a2a20eabd5e
7
+ data.tar.gz: c2fe63b4b819d5443750492371987cbdb75eaa0cb631b96bf6310cc9a078296f168263924fd93478ac4816b67abfb2168a89b11aac22d64090f79ee5ab7fc26b
data/README.md CHANGED
@@ -1,44 +1,20 @@
1
- # Paymium::Api
1
+ # Paymium ruby client [![Build Status](https://secure.travis-ci.org/Paymium/paymium_gem.png?branch=master)](http://travis-ci.org/Paymium/paymium_gem) [![Coverage Status](https://img.shields.io/coveralls/Paymium/paymium_gem.svg)](https://coveralls.io/r/Paymium/paymium_gem?branch=master) [![Gem Version](https://badge.fury.io/rb/paymium.svg)](http://badge.fury.io/rb/paymium)
2
2
 
3
- Simple ruby client to interract with the [paymium.com API](https://github.com/Paymium/api-documentation)
4
-
5
- Work in progress
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- gem 'paymium_api'
12
-
13
- And then execute:
14
-
15
- $ bundle
16
-
17
- Or install it yourself as:
18
-
19
- $ gem install paymium_api
3
+ Simple ruby wrapper for the [Paymium API](https://paymium.github.io/api-documentation/).
20
4
 
21
5
  ## Usage
22
6
 
23
7
  ```ruby
24
- @client = Paymium::Api::Client.new host: 'https://paymium.com/api/v1',
25
- key: "you api token",
26
- secret: "your api secret"
8
+ require 'paymium'
27
9
 
28
- @client.get('/data/EUR/ticker')
10
+ paymium = Paymium::Client.new({
11
+ host: 'https://paymium.com/api/v1',
12
+ key: '<api token>',
13
+ secret: '<api secret>'
14
+ })
29
15
 
30
- @client.get('/user')
31
- ````
16
+ paymium.get('/data/EUR/ticker')
32
17
 
33
- ## TODO
34
- - test merchants API
35
- - Dev oAuth api points
36
- - add delete method for orders's cancelations
37
-
38
- ## Contributing
18
+ paymium.get('/user')
19
+ ````
39
20
 
40
- 1. Fork it ( http://github.com/<my-github-username>/paymium_api/fork )
41
- 2. Create your feature branch (`git checkout -b my-new-feature`)
42
- 3. Commit your changes (`git commit -am 'Add some feature'`)
43
- 4. Push to the branch (`git push origin my-new-feature`)
44
- 5. Create new Pull Request
data/bin/paymium ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ $:.unshift File.join(File.dirname(__FILE__), '../lib')
3
+
4
+ require 'paymium'
5
+
6
+ puts "Paymium API wrapper v#{Paymium::VERSION}"
7
+ puts "This executable doesn't do anything yet"
8
+
@@ -0,0 +1,103 @@
1
+ require 'net/http'
2
+ require 'openssl'
3
+ require 'base64'
4
+
5
+ module Paymium
6
+
7
+ #
8
+ # Authenticated connection to the Paymium API
9
+ #
10
+ class Client
11
+
12
+ attr_accessor :config
13
+
14
+ #
15
+ # Initialize a client
16
+ #
17
+ # @param config [Hash] Symbol-keyed hash of the configuration
18
+ #
19
+ def initialize(config = {})
20
+ @config = config
21
+ @host = URI.parse @config.delete(:host) || Paymium::DEFAULT_HOST
22
+ end
23
+
24
+ #
25
+ # Issue a GET request against the API
26
+ #
27
+ # @param path [String] The request path
28
+ # @param params [Hash] The request parameters
29
+ #
30
+ def get(path, params = {}, &block)
31
+ uri = uri_from_path(path)
32
+ uri.query = URI.encode_www_form params unless params.empty?
33
+ request(Net::HTTP::Get.new(uri), &block)
34
+ end
35
+
36
+ #
37
+ # Issue a POST request against the API
38
+ #
39
+ # @param path [String] The request path
40
+ # @param params [Hash] The request parameters
41
+ #
42
+ def post(path, params = {}, &block)
43
+ req = Net::HTTP::Post.new(uri_from_path(path))
44
+ req.body = Oj.dump(params)
45
+ request(req, &block)
46
+ end
47
+
48
+ #
49
+ # Issue a DELETE request against the API
50
+ #
51
+ # @param path [String] The request path
52
+ # @param params [Hash] The request parameters
53
+ #
54
+ def delete(path, params = {}, &block)
55
+ uri = uri_from_path(path)
56
+ uri.query = URI.encode_www_form params unless params.empty?
57
+ request(Net::HTTP::Delete.new(uri), &block)
58
+ end
59
+
60
+ private
61
+
62
+ def set_header_fields(req)
63
+ key = @config[:key]
64
+ nonce = (Time.now.to_f * 10**6).to_i
65
+ data = [nonce, req.uri.to_s, req.body].compact.join
66
+ sig = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @config[:secret], data).strip
67
+ req.add_field "Api-Key", key
68
+ req.add_field "Api-Nonce", nonce
69
+ req.add_field "Api-Signature", sig
70
+ req
71
+ end
72
+
73
+ def uri_from_path(path)
74
+ uri = @host.dup
75
+ uri.path = "#{@host.path}/#{path}".gsub('//','/')
76
+ uri
77
+ end
78
+
79
+ def request(req, &block)
80
+ req.content_type = 'application/json'
81
+ set_header_fields(req) if @config[:key] and @config[:secret]
82
+ Net::HTTP.start(@host.host, @host.port, :use_ssl => @host.scheme == 'https') do |http|
83
+ resp = http.request(req)
84
+ handle_response(resp, &block)
85
+ end
86
+ end
87
+
88
+ def handle_response(resp, &block)
89
+ if resp.class == Net::HTTPNoContent
90
+ block.nil? ? nil : block.call(resp)
91
+ elsif resp.class < Net::HTTPSuccess
92
+ parsed_resp = Oj.load(resp.body)
93
+ block.nil? ? parsed_resp : block.call(resp)
94
+ else
95
+ raise Error, resp.body
96
+ end
97
+ end
98
+
99
+ # Generic Error class
100
+ class Error < RuntimeError; end
101
+
102
+ end
103
+ end
@@ -0,0 +1,6 @@
1
+ module Paymium
2
+
3
+ # The gem version
4
+ VERSION = '0.0.14'
5
+
6
+ end
data/lib/paymium.rb ADDED
@@ -0,0 +1,21 @@
1
+ require 'oj'
2
+
3
+ Oj.default_options = {
4
+ bigdecimal_load: true,
5
+ bigdecimal_as_decimal: true,
6
+ mode: :compat
7
+ }
8
+
9
+ require 'paymium/client'
10
+ require 'paymium/version'
11
+
12
+ #
13
+ # Root module
14
+ #
15
+ module Paymium
16
+
17
+ # Default API host
18
+ DEFAULT_HOST = 'https://paymium.com/api/v1'
19
+
20
+ end
21
+
metadata CHANGED
@@ -1,124 +1,159 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paymium_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
- - itkin
8
- autorequire:
7
+ - Paymium Tech
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2014-12-10 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: activesupport
13
+ name: oj
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
- - - '>='
16
+ - - ">="
18
17
  - !ruby/object:Gem::Version
19
18
  version: '0'
20
19
  type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
- - - '>='
23
+ - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: '0'
27
26
  - !ruby/object:Gem::Dependency
28
- name: json
27
+ name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
- - - '>='
30
+ - - "~>"
32
31
  - !ruby/object:Gem::Version
33
32
  version: '0'
34
- type: :runtime
33
+ type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
- - - '>='
37
+ - - "~>"
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
41
40
  - !ruby/object:Gem::Dependency
42
- name: bundler
41
+ name: rspec
43
42
  requirement: !ruby/object:Gem::Requirement
44
43
  requirements:
45
- - - ~>
44
+ - - "~>"
46
45
  - !ruby/object:Gem::Version
47
- version: '1.5'
46
+ version: '3'
48
47
  type: :development
49
48
  prerelease: false
50
49
  version_requirements: !ruby/object:Gem::Requirement
51
50
  requirements:
52
- - - ~>
51
+ - - "~>"
53
52
  - !ruby/object:Gem::Version
54
- version: '1.5'
53
+ version: '3'
55
54
  - !ruby/object:Gem::Dependency
56
- name: rake
55
+ name: simplecov
57
56
  requirement: !ruby/object:Gem::Requirement
58
57
  requirements:
59
- - - '>='
58
+ - - "~>"
60
59
  - !ruby/object:Gem::Version
61
- version: '0'
60
+ version: 0.16.1
62
61
  type: :development
63
62
  prerelease: false
64
63
  version_requirements: !ruby/object:Gem::Requirement
65
64
  requirements:
66
- - - '>='
65
+ - - "~>"
67
66
  - !ruby/object:Gem::Version
68
- version: '0'
67
+ version: 0.16.1
69
68
  - !ruby/object:Gem::Dependency
70
- name: pry
69
+ name: yard
71
70
  requirement: !ruby/object:Gem::Requirement
72
71
  requirements:
73
- - - '>='
72
+ - - "~>"
74
73
  - !ruby/object:Gem::Version
75
- version: '0'
74
+ version: 0.9.20
76
75
  type: :development
77
76
  prerelease: false
78
77
  version_requirements: !ruby/object:Gem::Requirement
79
78
  requirements:
80
- - - '>='
79
+ - - "~>"
81
80
  - !ruby/object:Gem::Version
82
- version: '0'
83
- description: Paymium API client
81
+ version: 0.9.20
82
+ - !ruby/object:Gem::Dependency
83
+ name: coveralls
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 0.8.23
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.8.23
96
+ - !ruby/object:Gem::Dependency
97
+ name: vcr
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 6.3.1
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 6.3.1
110
+ - !ruby/object:Gem::Dependency
111
+ name: webmock
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '3'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '3'
124
+ description: The client handles authentication and enables users to directly issue
125
+ requests to the Paymium API
84
126
  email:
85
- - nicolas.papon@webflows.fr
86
- executables: []
127
+ - tech@paymium.com
128
+ executables:
129
+ - paymium
87
130
  extensions: []
88
131
  extra_rdoc_files: []
89
132
  files:
90
- - .gitignore
91
- - .pryrc
92
- - Gemfile
93
- - LICENSE.txt
94
133
  - README.md
95
- - Rakefile
96
- - lib/paymium/api/client.rb
97
- - lib/paymium/api/version.rb
98
- - lib/paymium_api.rb
99
- - paymium_api.gemspec
100
- homepage: ''
134
+ - bin/paymium
135
+ - lib/paymium.rb
136
+ - lib/paymium/client.rb
137
+ - lib/paymium/version.rb
138
+ homepage: https://paymium.com
101
139
  licenses:
102
140
  - MIT
103
141
  metadata: {}
104
- post_install_message:
105
142
  rdoc_options: []
106
143
  require_paths:
107
144
  - lib
108
145
  required_ruby_version: !ruby/object:Gem::Requirement
109
146
  requirements:
110
- - - ~>
147
+ - - ">="
111
148
  - !ruby/object:Gem::Version
112
- version: '2.0'
149
+ version: 3.2.0
113
150
  required_rubygems_version: !ruby/object:Gem::Requirement
114
151
  requirements:
115
- - - '>='
152
+ - - ">="
116
153
  - !ruby/object:Gem::Version
117
154
  version: '0'
118
155
  requirements: []
119
- rubyforge_project:
120
- rubygems_version: 2.2.2
121
- signing_key:
156
+ rubygems_version: 3.6.7
122
157
  specification_version: 4
123
158
  summary: Paymium API client
124
159
  test_files: []
data/.gitignore DELETED
@@ -1,19 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- config.yaml
19
- .idea
data/.pryrc DELETED
@@ -1,7 +0,0 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
3
- require 'paymium_api'
4
- require 'yaml'
5
-
6
- # @client = Paymium::Api::Client.new YAML::load_file('config.yml')['token']
7
-
data/Gemfile DELETED
@@ -1,4 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- # Specify your gem's dependencies in paymium_api.gemspec
4
- gemspec
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2014 itkin
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile DELETED
@@ -1 +0,0 @@
1
- require "bundler/gem_tasks"
@@ -1,75 +0,0 @@
1
- require "active_support/hash_with_indifferent_access"
2
- require "active_support/core_ext/object/blank"
3
- require "net/http"
4
- require 'JSON'
5
-
6
- require 'openssl'
7
- require 'Base64'
8
-
9
-
10
- module Paymium
11
- module Api
12
- class Client
13
-
14
- def initialize config = {}
15
- @config = HashWithIndifferentAccess.new config
16
- @host = URI.parse @config.delete(:host)
17
- end
18
-
19
- def get path, params = {}, &block
20
- uri = uri_from_path(path)
21
- uri.query = URI.encode_www_form params unless params.empty?
22
- request Net::HTTP::Get.new(uri), &block
23
- end
24
-
25
- def post path, params = {}, &block
26
- req = Net::HTTP::Post.new(uri_from_path(path))
27
- req.body = params.to_json
28
- request req, &block
29
- end
30
-
31
-
32
- private
33
-
34
- def set_header_fields req
35
- key = @config[:key]
36
- nonce = (Time.now.to_f * 10**6).to_i
37
- data = [nonce, req.uri.to_s, req.body].compact.join
38
- sig = OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), @config[:secret], data).strip
39
- req.add_field "Api-Key", key
40
- req.add_field "Api-Nonce", nonce
41
- req.add_field "Api-Signature", sig
42
- req
43
- end
44
-
45
- def uri_from_path path
46
- uri = @host.dup
47
- uri.path = "#{@host.path}/#{path}".gsub('//','/')
48
- uri
49
- end
50
-
51
- def request req, &block
52
- req.content_type = 'application/json'
53
- set_header_fields(req) if @config[:key].present? and @config[:secret].present?
54
- Net::HTTP.start(@host.host, @host.port, :use_ssl => @host.scheme == 'https') do |http|
55
- resp = http.request req
56
- handle_response resp, &block
57
- end
58
- end
59
-
60
- #todo use Oj to parse response to handle big decimal
61
- def handle_response resp, &block
62
- if resp.class < Net::HTTPSuccess
63
- resp = JSON.parse(resp.body)
64
- block.nil? ? resp : block.call(resp)
65
- else
66
- raise Error, resp.message
67
- end
68
- end
69
-
70
- class Error < RuntimeError; end
71
-
72
- end
73
- end
74
- end
75
-
@@ -1,5 +0,0 @@
1
- module Paymium
2
- module Api
3
- VERSION = "0.0.5"
4
- end
5
- end
data/lib/paymium_api.rb DELETED
@@ -1,3 +0,0 @@
1
- require 'paymium/api/client'
2
- require 'paymium/api/version'
3
-
data/paymium_api.gemspec DELETED
@@ -1,27 +0,0 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'paymium/api/version'
5
-
6
- Gem::Specification.new do |spec|
7
- spec.name = "paymium_api"
8
- spec.version = Paymium::Api::VERSION
9
- spec.authors = ["itkin"]
10
- spec.email = ["nicolas.papon@webflows.fr"]
11
- spec.summary = %q{Paymium API client}
12
- spec.description = %q{Paymium API client}
13
- spec.homepage = ""
14
- spec.license = "MIT"
15
-
16
- spec.files = `git ls-files -z`.split("\x0")
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
20
- spec.required_ruby_version = '~> 2.0'
21
-
22
- spec.add_dependency 'activesupport'
23
- spec.add_dependency 'json'
24
- spec.add_development_dependency "bundler", "~> 1.5"
25
- spec.add_development_dependency "rake"
26
- spec.add_development_dependency "pry"
27
- end