blockchain-wallet 0.0.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: cf8b849e11d5dadb5af3bfa31bc78025295a5eb5
4
+ data.tar.gz: 4be8ac44d67885e26cc8bc31345b9860931e2f19
5
+ SHA512:
6
+ metadata.gz: fcfc3f27d50a70ddc6954ef4c412cf05e3b66d569af135a38bf7cec49deafd4ae2a4d9eb35a1d96ca72b0900af17478e20ccc7fa3640534b9d005ca63006e144
7
+ data.tar.gz: 5bc2c022e9546cb1a5f87c6f724ad145a2c7e8f2399af4b88e0c26312f7360f10a5bab1437a6ba3d2c00a283176735f2000234fe14fd17ebb87e5264fcf470df
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ # See http://help.github.com/ignore-files/ for more about ignoring files.
2
+ #
3
+ # If you find yourself ignoring temporary files generated by your text editor
4
+ # or operating system, you probably want to add a global ignore instead:
5
+ # git config --global core.excludesfile ~/.gitignore_global
6
+
7
+ # Ignore bundler config
8
+ /.bundle
9
+
10
+ *~
11
+ .*~
12
+ \#*\#
13
+ .\#*\#
14
+
15
+ .DS_Store
16
+ ._.DS_Store
17
+ .project
18
+ .settings
19
+ .directory
20
+
21
+ .rvmrc
22
+
23
+ log/*
24
+ tmp/*
25
+ db/*.sqlite3
26
+ db/schema.rb
27
+ public/system
28
+ .project
29
+ .idea/
30
+ public/uploads
31
+ public/javascripts/all*
32
+ public/stylesheets/all*
33
+ public/stylesheets/*.css
34
+ config/database.yml
35
+ webrat-*.html
36
+ capybara-*.html
37
+ rerun.txt
38
+ coverage.data
39
+ coverage/*
40
+ #*#
41
+ dump_for_download.dump
42
+ .~lock.*
43
+ C:\\nppdf32Log\\debuglog.txt
44
+
45
+ *.csv
46
+ *.iml
47
+ config/database.yml
48
+
49
+ Gemfile.lock
50
+ pkg/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in blockchain-wallet.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ Copyright (c) 2013 Sergey Tolmachev
2
+
3
+ Licensed by Creative Commons Attribution 3.0 Unported
4
+ http://creativecommons.org/licenses/by/3.0/
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # BlockchainWallet
2
+
3
+ Blockchain.info Wallet API for Ruby
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'blockchain-wallet'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install blockchain-wallet
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ desc 'Spec all functionality of gem'
4
+ task :spec_all do
5
+ system("rspec spec/*")
6
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'blockchain/wallet/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "blockchain-wallet"
8
+ spec.version = BlockchainWallet::VERSION
9
+ spec.authors = ["Sergey Tolmachev"]
10
+ spec.email = ["tolsi.ru@gmail.com"]
11
+ spec.description = "Blockchain.info Wallet API for Ruby"
12
+ spec.summary = ""
13
+ spec.homepage = ""
14
+ spec.license = "CC-BY"
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_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec"
24
+ spec.add_development_dependency "debase"
25
+ spec.add_development_dependency "ruby-debug-ide"
26
+
27
+ spec.add_dependency "immutable_struct"
28
+ spec.add_dependency "oj"
29
+ end
@@ -0,0 +1,77 @@
1
+ require File.expand_path('../wallet/version', __FILE__)
2
+ require File.expand_path('../web_api', __FILE__)
3
+ require "json"
4
+ require "oj"
5
+ require "immutable_struct"
6
+
7
+ module BlockchainWallet
8
+
9
+ class Wallet < WebAPI
10
+ def initialize(guid, password, second_password)
11
+ super("https://blockchain.info/merchant/#{guid}/")
12
+ @guid = guid
13
+ @password = password
14
+ @second_password = second_password
15
+ end
16
+
17
+ def addresses
18
+ url = build_url("list", {:password => @password})
19
+ handle(url) { |answer| answer.addresses }
20
+ end
21
+
22
+ def address_balance(address, confirmations = 0)
23
+ url = build_url("address_balance", {:password => @password, :address => address, :confirmations => confirmations})
24
+ handle(url) { |answer| answer }
25
+ end
26
+
27
+ def new_address(label='')
28
+ url = build_url("new_address", {:password => @password, :second_password => @second_password, :label => label})
29
+ handle(url) { |answer| answer }
30
+ end
31
+
32
+ def archive_address(address)
33
+ url = build_url("archive_address", {:password => @password, :second_password => @second_password, :address => address})
34
+ handle(url) { |answer| answer.archived == address }
35
+ end
36
+
37
+ def unarchive_address(address)
38
+ url = build_url("unarchive_address", {:password => @password, :second_password => @second_password, :address => address})
39
+ handle(url) { |answer| answer.active == address }
40
+ end
41
+
42
+ def auto_consolidate(days)
43
+ url = build_url("auto_consolidate", {:password => @password, :second_password => @second_password, :days => days})
44
+ handle(url) { |answer| answer.consolidated }
45
+ end
46
+
47
+ attr_reader :guid
48
+
49
+ private
50
+
51
+ class BlockchainException < Exception
52
+ end
53
+
54
+ def handle(url)
55
+ answer = execute_request(url)
56
+ check_error(answer)
57
+ yield ImmutableStruct.new(*answer.keys.map(&:to_sym)).new(*answer.values)
58
+ end
59
+
60
+ def execute_request(url)
61
+ json=open(URI.encode(url), :read_timeout => 10, :ssl_verify_mode => OpenSSL::SSL::VERIFY_NONE).read
62
+ parse_JSON(json)
63
+ rescue Exception => ex
64
+ raise BlockchainException, ex.message
65
+ end
66
+
67
+ def check_error(answer)
68
+ error = answer['error']
69
+ raise WebApiException, error if error
70
+ end
71
+
72
+ def parse_JSON(json)
73
+ Oj.load(json, :class_cache => true)
74
+ end
75
+
76
+ end
77
+ end
@@ -0,0 +1,3 @@
1
+ module BlockchainWallet
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,15 @@
1
+ require 'open-uri'
2
+
3
+ class WebAPI
4
+ def initialize(url)
5
+ @url=url
6
+ end
7
+
8
+ def build_url(operation_name, params)
9
+ @url + operation_name + "?" + params.map { |param, value| "#{param}=#{value}" }.join("&")
10
+ end
11
+
12
+
13
+ class WebApiException < Exception
14
+ end
15
+ end
@@ -0,0 +1,17 @@
1
+ require File.expand_path("../../lib/blockchain/wallet", __FILE__)
2
+
3
+ describe BlockchainWallet, ".addresses" do
4
+ it "returns all addresses" do
5
+ wallet = BlockchainWallet::Wallet.new("b14d36af-2fa6-4d76-91b5-ff70b8370ec7", "n$grJ74hAshfggnb6864%j78@#^hChttp://ya.ru@contentpurl", nil)
6
+ addresses=wallet.addresses
7
+ addresses.should_not be_empty
8
+ end
9
+ end
10
+
11
+ describe BlockchainWallet, "#addresses" do
12
+ it "returns all addresses" do
13
+ wallet = BlockchainWallet::Wallet.new("b14d36af-2fa6-4d76-91b5-ff70b8370ec7", "n$grJ74hAshfggnb6864%j78@#^hChttp://ya.ru@contentpurl", nil)
14
+ address_balance=wallet.address_balance("1JX7FrBm4Y96Z8BN6m9fWLN3bWVrEZ7dVs")
15
+ address_balance.balance.should >=(0)
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blockchain-wallet
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Sergey Tolmachev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-18 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
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: rspec
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
+ - !ruby/object:Gem::Dependency
56
+ name: debase
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: ruby-debug-ide
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
+ - !ruby/object:Gem::Dependency
84
+ name: immutable_struct
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: oj
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Blockchain.info Wallet API for Ruby
112
+ email:
113
+ - tolsi.ru@gmail.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - .gitignore
119
+ - Gemfile
120
+ - LICENSE
121
+ - README.md
122
+ - Rakefile
123
+ - blockchain-wallet.gemspec
124
+ - lib/blockchain/wallet.rb
125
+ - lib/blockchain/wallet/version.rb
126
+ - lib/blockchain/web_api.rb
127
+ - spec/BlockChainWalletSpec.rb
128
+ homepage: ''
129
+ licenses:
130
+ - CC-BY
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.1.9
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: ''
152
+ test_files:
153
+ - spec/BlockChainWalletSpec.rb