paymium_api 0.0.1

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: 1a7884a6381d42d4f1b6a2d6be500b064ce6325e
4
+ data.tar.gz: 6385ca52c28e43f056344e3fc0ff4d33d9d83fda
5
+ SHA512:
6
+ metadata.gz: 526a430cb2bf6b1467fe722d483fa448d8867d847a95cad23bc23a730ff27ae50058a8330eed3a00f49dd9c275c9810b00924e6b4b1f6977e5030c5400af1096
7
+ data.tar.gz: d8dd3d8422891a8fcd39e32966f7036755716431d1b3c491bd40b0513c521a1deb3864410d85502606da58a91d5b8fe77646e44c4026d1f0475d570b6c6d49f8
data/.gitignore ADDED
@@ -0,0 +1,19 @@
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 ADDED
@@ -0,0 +1,7 @@
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')
7
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in paymium_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
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/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # Paymium::Api
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
20
+
21
+ ## Usage
22
+
23
+ ```ruby
24
+ @client = Paymium::Api::Client.new host: 'https://paymium.com/api/v1',
25
+ key: "you api token",
26
+ secret: "your api secret"
27
+
28
+ @client.get('/data/EUR/ticker')
29
+
30
+ @client.get('/user')
31
+ ````
32
+
33
+ ## TODO
34
+ - test merchants API
35
+ - Dev oAuth api points
36
+ - add delete method for orders's cancelations
37
+
38
+ ## Contributing
39
+
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/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,8 @@
1
+ require 'paymium/api/client'
2
+ require 'paymium/api/version'
3
+
4
+ module Paymium
5
+ module Api
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,109 @@
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.set_form_data params unless params.empty?
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
+
76
+ # namespace :v1 do
77
+ # scope '/data/:currency', controller: :data do
78
+ # get 'ohlcv', to: :ohlcv
79
+ # get 'trades', to: :trades
80
+ # get 'latest_trades', to: :latest_trades
81
+ # get 'depth', to: :depth
82
+ # get 'ticker', to: :ticker
83
+ # end
84
+ #
85
+ # scope '/bitcoin_charts/:currency', controller: :bitcoin_charts do
86
+ # get 'depth', to: :depth
87
+ # get 'trades', to: :trades
88
+ # end
89
+ #
90
+ # post "sendgrid_events", controller: :sendgrid_events, action: :create
91
+ #
92
+ # scope '/merchant', controller: :merchant do
93
+ # post '/create_payment', to: :create_payment
94
+ # get '/get_payment/:uuid', to: :get_payment
95
+ # get '/get_payment_private/:uuid', to: :get_payment_private
96
+ # post '/create_payment_from_button/:uuid', to: :create_payment_from_button
97
+ # end
98
+ #
99
+ # resource :user, only: [:show] do
100
+ # resources :addresses, only: [:index, :show, :create]
101
+ # resources :payments, only: [:index, :show, :create]
102
+ # resources :orders, only: [:index, :show, :create] do
103
+ # member do
104
+ # delete :cancel
105
+ # end
106
+ # end
107
+ # end
108
+ # end
109
+ # end
@@ -0,0 +1,5 @@
1
+ module Paymium
2
+ module Api
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,26 @@
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/paymium/api.rb"]
20
+
21
+ spec.add_dependency 'activesupport'
22
+ spec.add_dependency 'json'
23
+ spec.add_development_dependency "bundler", "~> 1.5"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "pry"
26
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: paymium_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - itkin
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
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: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
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: pry
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
+ description: Paymium API client
84
+ email:
85
+ - nicolas.papon@webflows.fr
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .pryrc
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/paymium/api.rb
97
+ - lib/paymium/api/client.rb
98
+ - lib/paymium/api/version.rb
99
+ - paymium_api.gemspec
100
+ homepage: ''
101
+ licenses:
102
+ - MIT
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib/paymium/api.rb
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.1.11
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Paymium API client
124
+ test_files: []