xapo_sdk 0.0.1.pre.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: ad2e1b7257d3e2ff993c91b353a676a597c9def1
4
+ data.tar.gz: c8e76f1f93b6ca221ceec83b22fa75e9e4fd66e7
5
+ SHA512:
6
+ metadata.gz: 3cdec2146eabd4eda03bf489575af1d47c6682ac1a0d7b37db539bd17bb7cf79185cf1cbe5a34994f32affd8851de4c431203f73bce0708292c5793fa06600fe
7
+ data.tar.gz: af2f4663bbb24c9490cbcfb724e4657fa2e513afe467306df97deed5f0aee4d0ed4c71536b486d8c0627302ad9ba033c5cc8365b3c452cc7ed0bdc50b12adc67
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xapo_sdk.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,12 @@
1
+ Copyright (c) 2014, Xapo
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
5
+
6
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
7
+
8
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+
10
+ * Neither the name of Xapo SDK & Tools nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,160 @@
1
+ # README
2
+
3
+ >This is the Ruby version of the Xapo's Widget Tools. These tools allow you (Third Party Application, TPA) to easily embed tools like Payments Buttons, Donation Buttons and other kind of widgets as DIV or iFrame into your web application using your language of choice. In this way, tedious details like encryption and HTML snippet generation are handled for you in a simple and transparent way.
4
+
5
+ ---
6
+
7
+ <!-- START doctoc generated TOC please keep comment here to allow auto update -->
8
+ <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
9
+ ## Table of Contents
10
+
11
+ - [Table of Contents](#table-of-contents)
12
+ - [Build](#build)
13
+ - [Installation](#installation)
14
+ - [Micro Payment Widgets](#micro-payment-widgets)
15
+ - [IFrame Widget](#iframe-widget)
16
+ - [Div Widget](#div-widget)
17
+ - [Widgets Gallery](#widgets-gallery)
18
+ - [Contributing](#contributing)
19
+ - [TODO](#todo)
20
+
21
+ <!-- END doctoc generated TOC please keep comment here to allow auto update -->
22
+
23
+ ## Build
24
+
25
+ Ensure that tests pass:
26
+
27
+ $ rake test
28
+
29
+ Build the gem (output to `./pkg`):
30
+
31
+ $ rake build
32
+
33
+ And finally install de gem:
34
+
35
+ $ rake install
36
+
37
+ ## Installation
38
+
39
+ Add this line to your application's Gemfile:
40
+
41
+ ```ruby
42
+ gem 'xapo_sdk'
43
+ ```
44
+
45
+ And then execute:
46
+
47
+ $ bundle
48
+
49
+ Or install it yourself as:
50
+
51
+ $ gem install xapo_sdk
52
+
53
+ ## Micro Payment Widgets
54
+ Micro payment widgets allow to dynamically get a HTML snippet pre-configured and insert into your web page. Micro payment widgets provides 4 kind of pre-configured actions __Pay, Donate, Tip__ and __Deposit__. The widgets allow the following configurations:
55
+
56
+ - **Amount BIT:** `[optional]` sets a fixed amount for the intended payment.
57
+ - **Sender's Id:** `[optional]` any identifier used in the TPA context to identify the sender.
58
+ - **Sender's email:** `[optional]` used to pre-load the widget with the user's email.
59
+ - **Sender's cellphone:** `[optional]` used to pre-load the widget with the user's cellphone.
60
+ - **Receiver's Id:** `[mandatory]` any receiver's user unique identifier in the TPA context.
61
+ - **Receiver's email:** `[mandatory]` the email of the user receiving the payment. It allows XAPO to contact the receiver to claim her payment.
62
+ - **Pay Object's Id:** `[mandatory]` any unique identifier in the context of the TPA distinguishing the object of the payment.
63
+ - **Pay type:** `[optional]` any of Donate | Pay | Tip | Deposit.
64
+
65
+ ### IFrame Widget
66
+ ```ruby
67
+ require 'xapo_tools'
68
+
69
+ ...
70
+
71
+ micro_payment = XapoTools::MicroPayment.new(
72
+ XAPO_URL,
73
+ APP_ID,
74
+ APP_SECRET)
75
+ config = XapoTools.micro_payment_config
76
+
77
+ config[:sender_user_email] = "sender@xapo.com"
78
+ config[:sender_user_cellphone] = "+5491112341234"
79
+ config[:receiver_user_id] = "r0210"
80
+ config[:receiver_user_email] = "fernando.taboada@xapo.com"
81
+ config[:pay_object_id] = "to0210"
82
+ config[:amount_BIT] = 0.01
83
+ config[:pay_type] = PayType::DONATE
84
+
85
+ # Get IFRAME snippet
86
+ String iframe = microPayment.buildIframeWidget(request);
87
+ ```
88
+
89
+ With this you get the following snippet:
90
+
91
+ ```html
92
+ <iframe id='tipButtonFrame' scrolling='no' frameborder='0' style='border:none; overflow:hidden; height:22px;' allowTransparency='true' src='http://dev.xapo.com:8089/pay_button/show?customization=%7B%22button_text%22%3A%22Tip%22%7D&app_id=b91014cc28c94841&button_request=C%2F6OaxS0rh3jMhH90kRYyp3y%2BU5ADcCgMLCyz2P5ssFG%2FJoGf55ccvicyRMuIXpU5xhDeHGffpZAvVeMCpJhGFyIPwLFh%2FVdnjnDUjYgJCQeB4mCpGsEW5SC6wNvg69ksgeAtr108Wc5miA8H4JG99EWTTlC7WtIGg5rFKkbjrop15fSJfhv5cTs02jSC5f2BaLlh1mKh5hSPW3HGcWcl%2BdyZj%2F9m1lPB4gKfky2%2FnT0tYjbEFo5aU6WtowWrf2xE8OYejyI0poEFkClBkv2eDkp4Gel4tGb%2Bkwszcyb18ztK89RlBwhe8sX4HeM2KJM8ZaWuDOGH2VW4kbThMCZEw%3D%3D'></iframe>
93
+ ```
94
+
95
+ See the example results in the [widgets gallery](#widgets-gallery).
96
+
97
+ ### Div Widget
98
+ ```ruby
99
+ require 'xapo_tools'
100
+
101
+ ...
102
+
103
+ micro_payment = XapoTools::MicroPayment.new(
104
+ XAPO_URL,
105
+ APP_ID,
106
+ APP_SECRET)
107
+ config = XapoTools.micro_payment_config
108
+
109
+ config[:sender_user_email] = "sender@xapo.com"
110
+ config[:sender_user_cellphone] = "+5491112341234"
111
+ config[:receiver_user_id] = "r0210"
112
+ config[:receiver_user_email] = "fernando.taboada@xapo.com"
113
+ config[:pay_object_id] = "to0210"
114
+ config[:amount_BIT] = 0.01
115
+ config[:pay_type] = PayType::TIP
116
+
117
+ # PayType::TIP | PayType::PAY | PayType::DEPOSIT | PayType::DONATE
118
+ config[:pay_type] = PayType::DONATE
119
+
120
+ # Get DIV snippet
121
+ xapo_tools.build_div_widget(config)
122
+ ```
123
+
124
+ With this you get the following snippet:
125
+
126
+ ```html
127
+ <div id='tipButtonDiv' class='tipButtonDiv'></div>
128
+ <div id='tipButtonPopup' class='tipButtonPopup'></div>
129
+ <script>
130
+ $(document).ready(function() {$('#tipButtonDiv').load('http://dev.xapo.com:8089/pay_button/show?customization=%7B%22button_text%22%3A%22Donate%22%7D&app_id=b91014cc28c94841&button_request=C%2F6OaxS0rh3jMhH90kRYyp3y%2BU5ADcCgMLCyz2P5ssFG%2FJoGf55ccvicyRMuIXpU5xhDeHGffpZAvVeMCpJhGFyIPwLFh%2FVdnjnDUjYgJCQeB4mCpGsEW5SC6wNvg69ksgeAtr108Wc5miA8H4JG99EWTTlC7WtIGg5rFKkbjrop15fSJfhv5cTs02jSC5f2BaLlh1mKh5hSPW3HGcWcl%2BdyZj%2F9m1lPB4gKfky2%2FnT0tYjbEFo5aU6WtowWrf2xE8OYejyI0poEFkClBkv2eDkp4Gel4tGb%2Bkwszcyb18ztK89RlBwhe8sX4HeM2KJMHVfAM8NQXQu8oiIyCAl0vg%3D%3D');});
131
+ </script>
132
+ ```
133
+
134
+ See the example results in the [widgets gallery](#widgets-gallery).
135
+
136
+ ### Widgets Gallery
137
+
138
+ ![payment button](http://developers.xapo.com/images/payment_widget/donate_button.png)
139
+
140
+ ![payment phone](http://developers.xapo.com/images/payment_widget/mpayment1.png)
141
+
142
+ ![payment email](http://developers.xapo.com/images/payment_widget/mpayment2.png)
143
+
144
+ ![payment pin](http://developers.xapo.com/images/payment_widget/mpayment3.png)
145
+
146
+ ## Contributing
147
+
148
+ 1. Fork it ( https://github.com/xapo/ruby-sdk/fork )
149
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
150
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
151
+ 4. Push to the branch (`git push origin my-new-feature`)
152
+ 5. Create a new Pull Request
153
+
154
+ ## TODO
155
+ - ~~Fix style (https://github.com/bbatsov/ruby-style-guide#naming)~~
156
+ - ~~Add unit testing~~
157
+ - Document, document, ~~document~
158
+ - ~~Review naming and organization (with respect to Java & Python?)~~
159
+ - Review `gem` build infraestructure
160
+ - ...
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |task|
5
+ task.libs << %w(test lib)
6
+ task.pattern = 'test/test_*.rb'
7
+ end
8
+
9
+ task :default => :test
@@ -0,0 +1,3 @@
1
+ module XapoSdk
2
+ VERSION = "0.0.1-1"
3
+ end
data/lib/xapo_tools.rb ADDED
@@ -0,0 +1,81 @@
1
+ require "xapo_sdk/version"
2
+ require "xapo_utils"
3
+
4
+ require "json"
5
+ require "uri"
6
+ require "yaml"
7
+
8
+ module XapoTools
9
+
10
+ module_function
11
+
12
+ def micro_payment_config
13
+ return Hash[:sender_user_id => "", :sender_user_email => "",
14
+ :sender_user_cellphone => "", :receiver_user_id => "",
15
+ :receiver_user_email => "", :pay_object_id => "",
16
+ :amount_BIT => 0, :timestamp => XapoUtils.timestamp,
17
+ :pay_type => ""]
18
+ end
19
+
20
+ class MicroPayment
21
+ def initialize(service_url, app_id, app_secret)
22
+ @service_url = service_url
23
+ @app_id = app_id
24
+ @app_secret = app_secret
25
+ end
26
+
27
+ def build_url(config)
28
+ json_config = JSON.generate(config)
29
+ encrypted_config = XapoUtils.encrypt(json_config, @app_secret)
30
+
31
+ query_str = URI.encode_www_form(
32
+ "app_id" => @app_id,
33
+ "button_request" => encrypted_config,
34
+ "customization" => JSON.generate({"button_text" => config[:pay_type]}))
35
+
36
+ widget_url = @service_url + "?" + query_str
37
+
38
+ return widget_url
39
+ end
40
+
41
+ def build_iframe_widget(config)
42
+ widget_url = build_url(config)
43
+
44
+ snippet = YAML::load(<<-END)
45
+ |
46
+ <iframe id="tipButtonFrame" scrolling="no" frameborder="0"
47
+ style="border:none; overflow:hidden; height:22px;"
48
+ allowTransparency="true" src="#{widget_url}">
49
+ </iframe>
50
+ END
51
+
52
+ return snippet
53
+ end
54
+
55
+ def build_div_widget(config)
56
+ widget_url = build_url(config)
57
+
58
+ snippet = YAML::load(<<-END)
59
+ |
60
+ <div id="tipButtonDiv" class="tipButtonDiv"></div>
61
+ <div id="tipButtonPopup" class="tipButtonPopup"></div>
62
+ <script>
63
+ $(document).ready(function() {{
64
+ $("#tipButtonDiv").load("#{widget_url}");
65
+ }});
66
+ </script>
67
+ END
68
+
69
+ return snippet
70
+ end
71
+
72
+ private :build_url
73
+ end
74
+ end
75
+
76
+ module PayType
77
+ TIP = "Tip"
78
+ DONATE = "Donate"
79
+ PAY = "Pay"
80
+ DEPOSIT = "Deposit"
81
+ end
data/lib/xapo_utils.rb ADDED
@@ -0,0 +1,19 @@
1
+ require "openssl"
2
+ require "base64"
3
+
4
+ module XapoUtils
5
+
6
+ module_function
7
+
8
+ def encrypt(payload, secret)
9
+ cipher = OpenSSL::Cipher::AES.new("256-ECB")
10
+ cipher.encrypt
11
+ cipher.key = secret
12
+
13
+ encrypted = cipher.update(payload) + cipher.final
14
+
15
+ return Base64.encode64(encrypted)
16
+ end
17
+
18
+ def timestamp; (Time.now.to_f * 1000).to_i end
19
+ end
@@ -0,0 +1,46 @@
1
+ require "minitest/autorun"
2
+ require "xapo_tools"
3
+
4
+ class TestXapoTools < Minitest::Test
5
+ def setup
6
+ @xapo_tools = XapoTools::MicroPayment.new(
7
+ "http://dev.xapo.com:8089/pay_button/show",
8
+ "b91014cc28c94841",
9
+ "c533a6e606fb62ccb13e8baf8a95cbdc")
10
+ end
11
+
12
+ def test_build_iframe_widget()
13
+ config = XapoTools.micro_payment_config
14
+ config[:sender_user_email] = "sender@xapo.com"
15
+ config[:sender_user_cellphone] = "+5491112341234"
16
+ config[:receiver_user_id] = "r0210"
17
+ config[:receiver_user_email] = "fernando.taboada@xapo.com"
18
+ config[:pay_object_id] = "to0210"
19
+ config[:amount_BIT] = 0.01
20
+ config[:pay_type] = PayType::DONATE
21
+
22
+ actual = @xapo_tools.build_iframe_widget(config)
23
+
24
+ assert_match(/<iframe(.*)>(.*)<\/iframe>\n/m, actual)
25
+ end
26
+
27
+ def test_build_div_widget()
28
+ config = XapoTools.micro_payment_config
29
+ config[:sender_user_email] = "sender@xapo.com"
30
+ config[:sender_user_cellphone] = "+5491112341234"
31
+ config[:receiver_user_id] = "r0210"
32
+ config[:receiver_user_email] = "fernando.taboada@xapo.com"
33
+ config[:pay_object_id] = "to0210"
34
+ config[:amount_BIT] = 0.01
35
+ config[:pay_type] = PayType::TIP
36
+ regex = /
37
+ <div\sid="tipButtonDiv"\sclass="tipButtonDiv"><\/div>\n
38
+ <div\sid="tipButtonPopup"\sclass="tipButtonPopup"><\/div>\n
39
+ <script>(.*)<\/script>\n
40
+ /mx
41
+
42
+ actual = @xapo_tools.build_div_widget(config)
43
+
44
+ assert_match(regex, actual)
45
+ end
46
+ end
@@ -0,0 +1,28 @@
1
+ require 'minitest/autorun'
2
+ require 'xapo_utils'
3
+
4
+ class TestXapoUtils < Minitest::Test
5
+ def setup
6
+ end
7
+
8
+ def test_encrypt()
9
+ json = '{"sender_user_id":"s160901",' +
10
+ '"sender_user_email":"fernando.taboada@gmail.com",' +
11
+ '"sender_user_cellphone":"",' +
12
+ '"receiver_user_id":"r160901",' +
13
+ '"receiver_user_email":"fernando.taboada@xapo.com",' +
14
+ '"tip_object_id":"to160901",' +
15
+ '"amount_SAT":"",' +
16
+ '"timestamp":1410973639125}'
17
+ expected = 'rjiFHpE3794U23dEKNyEz3ukF5rhVxtKzxEnZq8opuHoRH5eA' +
18
+ '/XOEbROEzf5AYmyQ5Yw6cQLSVMx/JgENrNKVK268n3o1kOIxEpupaha2wYX' +
19
+ 'LqIqU8Ye7LFQz7NvQNPzfyOSPWnBQ/JUCSKsCiCz45VoK511B/RMz33mjJM' +
20
+ 'F7s2a6FEk6YOwf3hrvYwFt1frXLDwxsAwMXKUutIdfnrM2c6MYOFXTSGqZc' +
21
+ '2gS8DXmwHyIrXKUFCt7Ax3DMk0ao7iAE8MiXWaSSSZRVBQ7d1a9JDRoNtzq' +
22
+ 'GB++p7zK4NmOdrGEX9f+EwBjYuyKSsNez7kXPAWzwEvoi1o8gu4bxA1ng=='
23
+
24
+ actual = XapoUtils.encrypt(json, "bc4e142dc053407b0028accffc289c18").tr("\n","")
25
+
26
+ assert_equal(expected, actual)
27
+ end
28
+ end
data/xapo_sdk.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xapo_sdk/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "xapo_sdk"
8
+ spec.version = XapoSdk::VERSION
9
+ spec.authors = ["Federico Repond"]
10
+ spec.email = ["federico.repond@leapsight.com"]
11
+ spec.summary = %q{Xapo bitcoin sdk & tools.}
12
+ spec.description = %q{Xapo bitcoin sdk & tools.}
13
+ spec.homepage = ""
14
+ spec.license = "BSD"
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
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xapo_sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.pre.1
5
+ platform: ruby
6
+ authors:
7
+ - Federico Repond
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-31 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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
+ description: Xapo bitcoin sdk & tools.
42
+ email:
43
+ - federico.repond@leapsight.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - lib/xapo_sdk/version.rb
54
+ - lib/xapo_tools.rb
55
+ - lib/xapo_utils.rb
56
+ - test/test_xapo_tools.rb
57
+ - test/test_xapo_utils.rb
58
+ - xapo_sdk.gemspec
59
+ homepage: ''
60
+ licenses:
61
+ - BSD
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">"
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.1
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.4.2
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Xapo bitcoin sdk & tools.
83
+ test_files:
84
+ - test/test_xapo_tools.rb
85
+ - test/test_xapo_utils.rb
86
+ has_rdoc: