coin_market_cap 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,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGQ5Njg2ZjIxNGEzOTQwOTgyMjgxMWIxY2I1YmExOTRjNjgxYWRiNg==
5
+ data.tar.gz: !binary |-
6
+ MjM2ZTc5OGViNWRmYzNjYjRkOWQyZjJmMzhlZGYwNGI0NjhmYWRmYw==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YjVmY2YwOGM0NzY2ZTU2YTM2ZjExMWVjMTA3N2Y1ZDc3MDJmMTIwZDllZjA1
10
+ NTk0NjVjMGVlODVhNjUxNjlmNTYxYzNjMGZjYTA4MjY2Y2QyZmEwOTljZDM3
11
+ ODdiYjgxYTdkZDZhYmY5MTI4MTIyNTMzMmFhOTMxNDNkOWU0ODg=
12
+ data.tar.gz: !binary |-
13
+ YmRhYWU4ODIxNDZiZGMyZjY0YzExOTM1NDIzMzU4NjUyNzc1NDMxMmI1MTAy
14
+ OTRhNGU1ZGNmNmY0OTJmOWRkMmE5NDczNzBhNGNiNGQzZDM3YzgxMjliOTUy
15
+ M2IwYmM3ODcxYTcxMWU0YTIwNjJjMGM0ZDhkMGYxZjYxNjQ0MDQ=
data/.gitignore ADDED
@@ -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,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in coin_market_cap.gemspec
4
+ gem 'nokogiri'
5
+
6
+ gemspec
7
+
8
+ gem 'rspec'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 TODO: Write your name
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,37 @@
1
+ # Coin Market Cap
2
+
3
+ Ruby gem to fetch Crypto currency prices from Coin Market Cap
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'coin_market_cap'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install coin_market_cap
18
+
19
+ ## Usage
20
+
21
+ ### Price:
22
+
23
+ bitcoin = CoinMarketCap::Coin.new('bitcoin')
24
+
25
+ bitcoin.price
26
+ #=> 847.63
27
+
28
+ bitcoin.price_btc
29
+ #=> 1.00
30
+
31
+ ## Contributing
32
+
33
+ 1. Fork it ( http://github.com/<my-github-username>/coin_market_cap/fork )
34
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
35
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
36
+ 4. Push to the branch (`git push origin my-new-feature`)
37
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'rspec/core/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new('spec')
6
+
7
+ task :default => :spec
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'coin_market_cap/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "coin_market_cap"
8
+ spec.version = CoinMarketCap::VERSION
9
+ spec.platform = Gem::Platform::RUBY
10
+ spec.authors = ["Vinay Solanki"]
11
+ spec.email = ["vinaysolanki2005@gmail.com"]
12
+ spec.summary = %q{Coin Market Cap gem}
13
+ spec.description = %q{Ruby gem to fetch Crypto currency prices from Coin Market Cap}
14
+ spec.homepage = "http://github.com/vinaysolanki/coin_market_cap"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files`.split($/)
18
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency "nokogiri", "~> 1.6", ">=1.6.1"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake", "~> 10.1", ">=10.1.1"
26
+ spec.add_development_dependency "rspec", "~> 2.14", ">=2.14.1"
27
+ end
@@ -0,0 +1,8 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ require "open-uri"
5
+ require "nokogiri"
6
+
7
+ require "coin_market_cap/version"
8
+ require "coin_market_cap/coin"
@@ -0,0 +1,46 @@
1
+ module CoinMarketCap
2
+
3
+ # Coin class
4
+ class Coin
5
+ attr_accessor :coin
6
+
7
+ def initialize(coin)
8
+ @coin = coin.downcase
9
+ end
10
+
11
+ def sample_message
12
+ "Hello, World!"
13
+ end
14
+
15
+ def price
16
+ coin_price = fetch_coin_price(@coin, 'USD')
17
+ coin_price
18
+ end
19
+
20
+ def price_btc
21
+ coin_price = fetch_coin_price(@coin, 'BTC')
22
+ coin_price
23
+ end
24
+
25
+ private
26
+
27
+ def fetch_coin_price(coin, price_type)
28
+ doc = Nokogiri::HTML(open("http://www.coinmarketcap.com"))
29
+ currencies = {}
30
+
31
+ doc.css("#currencies tbody tr").each do |coin|
32
+ currency = coin.css(".no-wrap.currency-name a").text.downcase
33
+ if price_type == 'USD'
34
+ price = coin.css("td[4] a").attribute('data-usd').value.to_f
35
+ else
36
+ price = coin.css("td[4] a").attribute('data-btc').value.to_f
37
+ end
38
+ currencies[currency] = price
39
+ end
40
+
41
+ currencies[coin]
42
+ end
43
+
44
+ end
45
+ end
46
+
@@ -0,0 +1,3 @@
1
+ module CoinMarketCap
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe CoinMarketCap do
4
+
5
+ it "should display sample message" do
6
+ sample_message = CoinMarketCap::Coin.new('bitcoin').sample_message
7
+ expect(sample_message).to eq("Hello, World!")
8
+ end
9
+
10
+ it "should return price of the coin" do
11
+ coin = CoinMarketCap::Coin.new('bitcoin')
12
+ expect(coin.price).to be_kind_of(Float)
13
+ coin = CoinMarketCap::Coin.new('litecoin')
14
+ expect(coin.price).to be_kind_of(Float)
15
+ end
16
+
17
+ it "should return price of coin in BTC" do
18
+ coin = CoinMarketCap::Coin.new('bitcoin')
19
+ expect(coin.price_btc).to eq(1.00)
20
+ end
21
+
22
+ end
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'coin_market_cap'
4
+
5
+ RSpec.configure do |config|
6
+
7
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: coin_market_cap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Vinay Solanki
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: nokogiri
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 1.6.1
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.6'
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 1.6.1
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ~>
38
+ - !ruby/object:Gem::Version
39
+ version: '1.5'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '1.5'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '10.1'
54
+ - - ! '>='
55
+ - !ruby/object:Gem::Version
56
+ version: 10.1.1
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ~>
62
+ - !ruby/object:Gem::Version
63
+ version: '10.1'
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: 10.1.1
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: '2.14'
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: 2.14.1
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ~>
82
+ - !ruby/object:Gem::Version
83
+ version: '2.14'
84
+ - - ! '>='
85
+ - !ruby/object:Gem::Version
86
+ version: 2.14.1
87
+ description: Ruby gem to fetch Crypto currency prices from Coin Market Cap
88
+ email:
89
+ - vinaysolanki2005@gmail.com
90
+ executables: []
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - .gitignore
95
+ - Gemfile
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - coin_market_cap.gemspec
100
+ - lib/coin_market_cap.rb
101
+ - lib/coin_market_cap/coin.rb
102
+ - lib/coin_market_cap/version.rb
103
+ - spec/coin_market_cap_spec.rb
104
+ - spec/spec_helper.rb
105
+ homepage: http://github.com/vinaysolanki/coin_market_cap
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Coin Market Cap gem
129
+ test_files:
130
+ - spec/coin_market_cap_spec.rb
131
+ - spec/spec_helper.rb