bitcoinaverage 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,6 @@
1
+ Gemfile.lock
2
+ coverage/*
3
+ log/*
4
+ *.gem
5
+ mysession
6
+ mysession.vim
@@ -0,0 +1,6 @@
1
+ bundler_args: --without development
2
+ language: ruby
3
+ rvm:
4
+ - 1.9.3-p374
5
+ - 2.0.0-rc1
6
+ - 2.1.0
data/Gemfile ADDED
@@ -0,0 +1,18 @@
1
+ # A sample Gemfile
2
+ source "https://rubygems.org"
3
+
4
+ gem 'httparty'
5
+ gem 'json'
6
+ group :development do
7
+ gem 'pry'
8
+ gem 'pry-nav'
9
+ end
10
+
11
+ group :test do
12
+ gem 'rspec', '>= 2.14'
13
+ gem 'coveralls', require: false
14
+ gem 'webmock'
15
+ gem 'simplecov'
16
+ end
17
+
18
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Toni Urcola
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,75 @@
1
+ # Ruby wrapper for the BitcoinAverage API
2
+
3
+ [![Gem Version]][gem]
4
+ [![Coverage Status](https://coveralls.io/repos/git-toni/bitcoinaverage/badge.png)](https://coveralls.io/r/git-toni/bitcoinaverage)
5
+ [gem]: https://rubygems.org/gems/bitcoinaverage
6
+ [travis]: https://github.com/git-toni/bitcoinaverage
7
+
8
+
9
+
10
+ Bitcoinaverage is an independent 'globally averaged bitcoin price' provider. They provide a **Global** price,
11
+ based on the volume and price of BTC in all currencies, together with a **Market** price, which only takes into account
12
+ the volume of BTC directly exchangeable through that specific currency.
13
+ For more information on the methods BitcoinAverage uses to calculate the price, please refer to their website, in
14
+ particular [this page](https://bitcoinaverage.com/explain.htm).
15
+
16
+ ## Important first note
17
+ The development of this gem has been *deeply* inspired by Erik Michaels-Ober's great [mtgox](https://github.com/sferik/mtgox) gem ( specially this README ;) ).
18
+
19
+ ## Installation
20
+ gem install bitcoinaverage
21
+
22
+
23
+ ## Documentation
24
+ TODO
25
+
26
+ ## Usage
27
+ ```ruby
28
+ require 'rubygems'
29
+ require 'bitcoinaverage'
30
+
31
+ # Obtain the BitcoinAverage's global price
32
+ BitcoinAverage.global
33
+
34
+ # Obtain the BitcoinAverage's market price
35
+ BitcoinAverage.market
36
+
37
+ # Obtain the BitcoinAverage's global price in EUR
38
+ BitcoinAverage.global 'EUR'
39
+
40
+ # Obtain the BitcoinAverage's market price in GBP
41
+ BitcoinAverage.market 'GBP'
42
+
43
+ # Obtain the specific fields of BitcoinAverage's global price
44
+ BitcoinAverage.global.last
45
+ BitcoinAverage.global.bid
46
+ BitcoinAverage.global.ask
47
+ BitcoinAverage.global.volume_btc
48
+ BitcoinAverage.global.volume_percent
49
+ ```
50
+
51
+ ## Tested Ruby Versions
52
+ This library aims to support and is [tested against][travis] the following Ruby
53
+ implementations:
54
+
55
+ * ruby-1.9.3-p374
56
+ * ruby-2.0.0-rc1
57
+ * ruby-2.1.0
58
+
59
+ ## Contributing
60
+ In the spirit of [free software](http://www.fsf.org/licensing/essays/free-sw.html), **everyone** is encouraged to help improve this project.
61
+
62
+ Here are some ways *you* can contribute:
63
+
64
+ * by using alpha, beta, and prerelease versions
65
+ * by reporting bugs
66
+ * by suggesting new features
67
+ * by writing or editing documentation
68
+ * by writing specifications
69
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up inconsistent whitespace)
70
+ * by refactoring code
71
+ * by closing [issues](http://github.com/Instagram/instagram-ruby-gem/issues)
72
+ * by reviewing patches
73
+
74
+ ## Copyright
75
+ Copyright (c) 2014 Toni Urcola. See [LICENSE](https://github.com/git-toni/bitcoinaverage/LICENSE) for details.
@@ -0,0 +1,21 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+ require 'bitcoinaverage/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'bitcoinaverage'
6
+ s.version = BitcoinAverage::VERSION
7
+ s.summary = "Ruby Wrapper for the Bitcoinaverage API"
8
+ s.description = "Ruby wrapper for the Bitcoinaverage API. Bitcoinaverage is an independent 'globally averaged bitcoin price' provider"
9
+ s.author = ["Toni Urcola"]
10
+ s.email = 'unmail.toni@gmail.com'
11
+ s.files = `git ls-files`.split("\n")
12
+ s.test_files = `git ls-files -- {test,spec}/*`.split("\n")
13
+ s.require_paths = ["lib"]
14
+ s.required_ruby_version = '>= 1.9.3'
15
+ s.add_dependency 'httparty'
16
+ s.add_dependency 'json'
17
+ s.add_development_dependency 'rspec'
18
+ s.add_development_dependency 'bundler'
19
+ s.homepage = 'http://rubygems.org/gems/bitcoinaverage'
20
+ s.license = 'MIT'
21
+ end
@@ -0,0 +1,11 @@
1
+ require 'bitcoinaverage/market_ticker'
2
+ require 'bitcoinaverage/global_ticker'
3
+
4
+ module BitcoinAverage
5
+ def self.global(currency="USD")
6
+ GlobalTicker.instance.request_info currency
7
+ end
8
+ def self.market(currency="USD")
9
+ MarketTicker.instance.request_info currency
10
+ end
11
+ end
@@ -0,0 +1 @@
1
+ AED,AFN,ALL,AMD,ANG,AOA,ARS,AUD,AWG,AZN,BAM,BBD,BDT,BGN,BHD,BIF,BMD,BND,BOB,BRL,BSD,BTC,BTN,BWP,BYR,BZD,CAD,CDF,CHF,CLF,CLP,CNY,COP,CRC,CUP,CVE,CZK,DJF,DKK,DOP,DZD,EEK,EGP,ERN,ETB,EUR,FJD,FKP,GBP,GEL,GHS,GIP,GMD,GNF,GTQ,GYD,HKD,HNL,HRK,HTG,HUF,IDR,ILS,INR,IQD,IRR,ISK,JEP,JMD,JOD,JPY,KES,KGS,KHR,KMF,KPW,KRW,KWD,KYD,KZT,LAK,LBP,LKR,LRD,LSL,LTL,LVL,LYD,MAD,MDL,MGA,MKD,MMK,MNT,MOP,MRO,MTL,MUR,MVR,MWK,MXN,MYR,MZN,NAD,NGN,NIO,NOK,NPR,NZD,OMR,PAB,PEN,PGK,PHP,PKR,PLN,PYG,QAR,RON,RSD,RUB,RWF,SAR,SBD,SCR,SDG,SEK,SGD,SHP,SLL,SOS,SRD,STD,SVC,SYP,SZL,THB,TJS,TMT,TND,TOP,TRY,TTD,TWD,TZS,UAH,UGX,USD,UYU,UZS,VEF,VND,VUV,WST,XAF,XAG,XAU,XCD,XDR,XOF,XPF,YER,ZAR,ZMK,ZMW,ZWL
@@ -0,0 +1,12 @@
1
+ require 'bitcoinaverage/ticker'
2
+ require 'singleton'
3
+
4
+ module BitcoinAverage
5
+ class GlobalTicker < BitcoinAverage::Ticker
6
+ include Singleton
7
+ attr_accessor :volume_btc, :volume_percent
8
+ def avg_type
9
+ 'global'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ require 'bitcoinaverage/ticker'
2
+ require 'singleton'
3
+
4
+ module BitcoinAverage
5
+ class MarketTicker < BitcoinAverage::Ticker
6
+ include Singleton
7
+ attr_accessor :total_vol
8
+ def avg_type
9
+ 'market'
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,37 @@
1
+ require 'httparty'
2
+
3
+ module BitcoinAverage
4
+ module Requester
5
+ def sendrequest(average,currency='USD')
6
+ raise "#{currency} is not a known currency" unless known_currency?(currency)
7
+ base_url='https://api.bitcoinaverage.com/ticker/'
8
+ avg_url= average == 'global'? average+'/' : ''
9
+ ccy_url=currency
10
+ final_url= base_url+avg_url+ccy_url
11
+
12
+ response=HTTParty.get final_url
13
+ end
14
+
15
+ def known_currency?(currency)
16
+ av_currencies=File.open('lib/bitcoinaverage/available_currencies.csv','r')
17
+ .read
18
+ .parse_csv
19
+ true unless !av_currencies.include? currency
20
+ end
21
+
22
+ #Method to obtain all the available currencies
23
+ #
24
+ #Note: it's not run repeatedly, rather the result
25
+ #was written to a file.
26
+ #Note 2: "require 'csv' " is necessary for this method
27
+ #
28
+ #
29
+ #def available_currencies
30
+ # all_ccy=HTTParty.get 'https://api.bitcoinaverage.com/ticker/global/all'
31
+ # all_ccy.map!{|k,v| k}
32
+ # file= File.open 'currencies_file.csv','w'
33
+ # file.write all_ccy[0..-2].to_csv
34
+ # file.close
35
+ #end
36
+ end
37
+ end
@@ -0,0 +1,26 @@
1
+ require 'bitcoinaverage/requester'
2
+ require 'json'
3
+
4
+ module BitcoinAverage
5
+ class Ticker
6
+ include BitcoinAverage::Requester
7
+ attr_accessor :avg_24h, :ask, :bid, :last, :timestamp
8
+
9
+ def request_info currency='USD'
10
+ response= sendrequest self.avg_type, currency
11
+ if response.success?
12
+ #Small patch since an attribute can't be named "24h_avg"
13
+ response=JSON.load(response.to_s) unless response.is_a?(Hash)
14
+ self.avg_24h = response["24h_avg"]
15
+ response.delete("24h_avg")
16
+ #binding.pry
17
+ response.each do |key,value|
18
+ send("#{key}=",value)
19
+ end
20
+ self
21
+ else
22
+ raise "Error receiving response"#<- to be extended
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,3 @@
1
+ module BitcoinAverage
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,52 @@
1
+ require 'spec_helper'
2
+ require 'bitcoinaverage'
3
+
4
+ SimpleCov.start
5
+ describe BitcoinAverage do
6
+ describe '.global ' do
7
+ before do
8
+ stub_request(:get, "https://api.bitcoinaverage.com/ticker/global/USD").
9
+ to_return(status:200, body: fixture('global_USD.json'),headers:{})
10
+ @response=BitcoinAverage.global
11
+ end
12
+ it 'returns a GlobalTicker object properly filled' do
13
+ #binding.pry
14
+ #expect(BitcoinAverage.global).to be_a BitcoinAverage::GlobalTicker
15
+ expect(@response).to be_a BitcoinAverage::GlobalTicker
16
+ @response.avg_24h.should == 568.44
17
+ @response.ask.should == 566.15
18
+ @response.bid.should == 563.83
19
+ @response.last.should == 564.61
20
+ @response.timestamp.should == 'Fri, 21 Feb 2014 16:22:17 -0000'
21
+ @response.volume_btc.should == 100496.08
22
+ @response.volume_percent.should == 79.49
23
+ end
24
+ end
25
+ describe '.market ' do
26
+ before do
27
+ stub_request(:get, "https://api.bitcoinaverage.com/ticker/USD").
28
+ to_return(status:200, body: fixture('market_USD.json'),headers:{})
29
+ @response=BitcoinAverage.market
30
+ end
31
+ it 'returns a GlobalTicker object properly filled' do
32
+ #binding.pry
33
+ #expect(BitcoinAverage.global).to be_a BitcoinAverage::GlobalTicker
34
+ expect(@response).to be_a BitcoinAverage::MarketTicker
35
+ @response.avg_24h.should == 565.89
36
+ @response.ask.should == 562.54
37
+ @response.bid.should == 559.7
38
+ @response.last.should == 560.54
39
+ @response.timestamp.should == 'Fri, 21 Feb 2014 16:24:27 -0000'
40
+ @response.total_vol.should == 100667.13
41
+ end
42
+ end
43
+ describe 'unknown currency' do
44
+ before do
45
+ stub_request(:get, "https://api.bitcoinaverage.com/ticker/EEE").
46
+ to_return(status:404, body:"", headers:{})
47
+ end
48
+ it 'raises an error' do
49
+ expect{BitcoinAverage.market('EEE')}.to raise_error("EEE is not a known currency")
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,9 @@
1
+ {
2
+ "24h_avg": 414.43,
3
+ "ask": 411.77,
4
+ "bid": 410.41,
5
+ "last": 410.77,
6
+ "timestamp": "Fri, 21 Feb 2014 16:23:25 -0000",
7
+ "volume_btc": 4337.36,
8
+ "volume_percent": 3.43
9
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ "24h_avg": 568.44,
3
+ "ask": 566.15,
4
+ "bid": 563.83,
5
+ "last": 564.61,
6
+ "timestamp": "Fri, 21 Feb 2014 16:22:17 -0000",
7
+ "volume_btc": 100496.08,
8
+ "volume_percent": 79.49
9
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "24h_avg": 419.29,
3
+ "ask": 420.16,
4
+ "bid": 417.84,
5
+ "last": 418.17,
6
+ "timestamp": "Fri, 21 Feb 2014 16:24:27 -0000",
7
+ "total_vol": 4335.29
8
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "24h_avg": 565.89,
3
+ "ask": 562.54,
4
+ "bid": 559.7,
5
+ "last": 560.54,
6
+ "timestamp": "Fri, 21 Feb 2014 16:24:27 -0000",
7
+ "total_vol": 100667.13
8
+ }
@@ -0,0 +1,23 @@
1
+ #require 'pry'
2
+ require 'simplecov'
3
+ require 'coveralls'
4
+
5
+ SimpleCov.start
6
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
7
+ SimpleCov::Formatter::HTMLFormatter,
8
+ Coveralls::SimpleCov::Formatter
9
+ ]
10
+ #Coveralls.wear!
11
+
12
+
13
+ require 'pry'
14
+ require 'rspec'
15
+ require 'webmock/rspec'
16
+ WebMock.disable_net_connect!(allow:'coverwalls.io',allow_localhost:true)
17
+
18
+ def fixture_path
19
+ File.expand_path('../fixtures', __FILE__)
20
+ end
21
+ def fixture(file)
22
+ File.new(fixture_path + '/' + file)
23
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bitcoinaverage
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Toni Urcola
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2014-02-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: json
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: bundler
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: Ruby wrapper for the Bitcoinaverage API. Bitcoinaverage is an independent
79
+ 'globally averaged bitcoin price' provider
80
+ email: unmail.toni@gmail.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .bitcoinaverage.gemspec.swp
86
+ - .gitignore
87
+ - .travis.yml
88
+ - Gemfile
89
+ - LICENSE
90
+ - README.md
91
+ - bitcoinaverage.gemspec
92
+ - coverage/.last_run.json
93
+ - coverage/.resultset.json
94
+ - coverage/assets/0.8.0/application.css
95
+ - coverage/assets/0.8.0/application.js
96
+ - coverage/assets/0.8.0/colorbox/border.png
97
+ - coverage/assets/0.8.0/colorbox/controls.png
98
+ - coverage/assets/0.8.0/colorbox/loading.gif
99
+ - coverage/assets/0.8.0/colorbox/loading_background.png
100
+ - coverage/assets/0.8.0/favicon_green.png
101
+ - coverage/assets/0.8.0/favicon_red.png
102
+ - coverage/assets/0.8.0/favicon_yellow.png
103
+ - coverage/assets/0.8.0/loading.gif
104
+ - coverage/assets/0.8.0/magnify.png
105
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png
106
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_flat_75_ffffff_40x100.png
107
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png
108
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_glass_65_ffffff_1x400.png
109
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_dadada_1x400.png
110
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png
111
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png
112
+ - coverage/assets/0.8.0/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png
113
+ - coverage/assets/0.8.0/smoothness/images/ui-icons_222222_256x240.png
114
+ - coverage/assets/0.8.0/smoothness/images/ui-icons_2e83ff_256x240.png
115
+ - coverage/assets/0.8.0/smoothness/images/ui-icons_454545_256x240.png
116
+ - coverage/assets/0.8.0/smoothness/images/ui-icons_888888_256x240.png
117
+ - coverage/assets/0.8.0/smoothness/images/ui-icons_cd0a0a_256x240.png
118
+ - coverage/index.html
119
+ - lib/bitcoinaverage.rb
120
+ - lib/bitcoinaverage/available_currencies.csv
121
+ - lib/bitcoinaverage/global_ticker.rb
122
+ - lib/bitcoinaverage/market_ticker.rb
123
+ - lib/bitcoinaverage/requester.rb
124
+ - lib/bitcoinaverage/ticker.rb
125
+ - lib/bitcoinaverage/version.rb
126
+ - mysession
127
+ - spec/bitcoinaverage_spec.rb
128
+ - spec/fixtures/global_EUR.json
129
+ - spec/fixtures/global_USD.json
130
+ - spec/fixtures/market_EUR.json
131
+ - spec/fixtures/market_USD.json
132
+ - spec/spec_helper.rb
133
+ homepage: http://rubygems.org/gems/bitcoinaverage
134
+ licenses:
135
+ - MIT
136
+ post_install_message:
137
+ rdoc_options: []
138
+ require_paths:
139
+ - lib
140
+ required_ruby_version: !ruby/object:Gem::Requirement
141
+ none: false
142
+ requirements:
143
+ - - ! '>='
144
+ - !ruby/object:Gem::Version
145
+ version: 1.9.3
146
+ required_rubygems_version: !ruby/object:Gem::Requirement
147
+ none: false
148
+ requirements:
149
+ - - ! '>='
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ requirements: []
153
+ rubyforge_project:
154
+ rubygems_version: 1.8.24
155
+ signing_key:
156
+ specification_version: 3
157
+ summary: Ruby Wrapper for the Bitcoinaverage API
158
+ test_files: []
159
+ has_rdoc: