vpy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in vpy.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Philippe Creux
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.
@@ -0,0 +1,37 @@
1
+ # Vpy - The Versapay Gem
2
+
3
+ Send money via Versapay from the CLI
4
+
5
+
6
+ ## Send money from the command line
7
+
8
+ Install it:
9
+
10
+ $ gem install vpy
11
+
12
+ Set the environment variables `VERSAPAY_KEY` and `VERSAPAY_TOKEN`.
13
+
14
+ Run:
15
+
16
+ $ versapay send 10.23 bob@example.com
17
+
18
+ ... with a message:
19
+
20
+ $ versapay send 10.23 bob@example.com "Here is some cash"
21
+
22
+ ... against demo environment:
23
+
24
+ $ versapay send 10.23 bob@example.com --demo
25
+
26
+ ## Send money from ruby
27
+
28
+ ```ruby
29
+ require 'vpy'
30
+
31
+ client = Versapay.new(VERSAPAY_TOKEN, VERSAPAY_KEY)
32
+ client.send(10.23, 'bob@example.com')
33
+ ```
34
+
35
+ ## License
36
+
37
+ MIT
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ require 'versapay'
2
+
3
+ Versapay::CLI.start
@@ -0,0 +1,3 @@
1
+ require "versapay/version"
2
+ require "versapay/client"
3
+ require "versapay/cli"
@@ -0,0 +1,26 @@
1
+ require "thor"
2
+ module Versapay
3
+ class CLI < Thor
4
+ class_option :demo, type: :boolean
5
+
6
+ desc "send AMOUNT EMAIL [MESSAGE] (--demo)", "send AMOUNT to EMAIL with MESSAGE"
7
+ def send(amount, email, message=nil)
8
+ client = Client.new(
9
+ ENV.fetch('VERSAPAY_TOKEN'),
10
+ ENV.fetch('VERSAPAY_KEY'),
11
+ options[:demo] ? 'demo' : 'secure'
12
+ )
13
+
14
+ human_amount = "%.2f" % amount.to_f
15
+ answer = ask "Send $#{human_amount} to #{email} ?"
16
+
17
+ say "Running in demo environment..." if options[:demo]
18
+
19
+ if answer.downcase.strip =~ /^y(es)?$/
20
+ say "Sending $#{human_amount} to <#{email}>..."
21
+ response = client.send(amount, email, message)
22
+ puts "Success! Transaction token: #{response.fetch('token')}"
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ require "rest-client"
2
+ require "json"
3
+
4
+ module Versapay
5
+ class Client
6
+ def initialize(user, password, environment='secure')
7
+ @user = user
8
+ @password = password
9
+ @environment = environment
10
+ end
11
+
12
+ attr_reader :user, :password, :environment
13
+
14
+ def url
15
+ "https://#{user}:#{password}@#{environment}.versapay.com/api/transactions.json"
16
+ end
17
+
18
+ def send(amount, email, message=nil)
19
+ amount_in_cents = (amount.to_f * 100).to_i
20
+
21
+ payload = {
22
+ transaction_type: 'send',
23
+ email: email,
24
+ amount_in_cents: amount_in_cents,
25
+ message: message
26
+ }.to_json
27
+
28
+ response_hash = nil
29
+
30
+ RestClient.post(url, payload, content_type: :json, accept: :json) do |response, request, result, &block|
31
+ unless response.code == 201
32
+ raise "Error: #{JSON.parse(response.body).inspect}"
33
+ end
34
+ response_hash = JSON.parse(response.body)
35
+ end
36
+
37
+ response_hash
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module Versapay
2
+ VERSION = "0.0.1"
3
+ 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 'versapay/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vpy"
8
+ spec.version = Versapay::VERSION
9
+ spec.authors = ["Philippe Creux"]
10
+ spec.email = ["pcreux@gmail.com"]
11
+ spec.description = %q{Versapay command line tool}
12
+ spec.summary = %q{Send and request money via Versapay from the command line}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
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
+
21
+ spec.add_dependency "thor"
22
+ spec.add_dependency "rest-client"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vpy
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Philippe Creux
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: thor
16
+ requirement: &70280006115440 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70280006115440
25
+ - !ruby/object:Gem::Dependency
26
+ name: rest-client
27
+ requirement: &70280006112980 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70280006112980
36
+ - !ruby/object:Gem::Dependency
37
+ name: bundler
38
+ requirement: &70280006111140 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: '1.3'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *70280006111140
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: &70280006131640 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *70280006131640
58
+ description: Versapay command line tool
59
+ email:
60
+ - pcreux@gmail.com
61
+ executables:
62
+ - versapay
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - .gitignore
67
+ - Gemfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/versapay
72
+ - lib/versapay.rb
73
+ - lib/versapay/cli.rb
74
+ - lib/versapay/client.rb
75
+ - lib/versapay/version.rb
76
+ - vpy.gemspec
77
+ homepage: ''
78
+ licenses:
79
+ - MIT
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ segments:
91
+ - 0
92
+ hash: -240432159398585266
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ! '>='
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ segments:
100
+ - 0
101
+ hash: -240432159398585266
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 1.8.11
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Send and request money via Versapay from the command line
108
+ test_files: []