currency_by_ip 0.1.0

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: 046e914f478a80c16bcfd507bcf3330ec343f718
4
+ data.tar.gz: a652a23498ada22b8bb58addcc12f0e433d67368
5
+ SHA512:
6
+ metadata.gz: b6e78f46dada901fc4af0a893974fc6cf5ee26934009d00b4d380e1b993712470874b777ab5caa16ef2dc1cf6289a43e77125a3ec630d7f3ff5c878a0d53cc12
7
+ data.tar.gz: 248a6b970576b2cc7daf2c9f11b66c06b0dbeb3e3327111aaef4e40dc6f0451d124740f9a99815566e4c9b9025f6f679c073374350d89535b5a4984b24d98a5f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in currency_by_ip.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Sunny Ripert
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # CurrencyByIp
2
+
3
+ Guess the currency to show a user from his IP address. This uses GeoIP's IP
4
+ database.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'currency_by_ip'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ ## GeoIP
19
+
20
+ Please download an up-to-date decompressed `GeoIP.dat` from:
21
+ http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
22
+ and place it somewhere in your app, like `lib/geo/GeoIP.dat`.
23
+
24
+ ## Usage
25
+
26
+ ```ruby
27
+ CurrencyByIp.find_by_ip("173.194.34.1",
28
+ geoip_data_path: "lib/geo/GeoIP.dat") # => "USD"
29
+ ```
30
+
31
+ ## Development
32
+
33
+ After checking out the repo, run `bin/setup` to install dependencies. Then,
34
+ run `bin/console` for an interactive prompt that will allow you to experiment.
35
+
36
+ To install this gem onto your local machine, run `bundle exec rake install`.
37
+ To release a new version, update the version number in `version.rb`, and then
38
+ run `bundle exec rake release` to create a git tag for the version, push git
39
+ commits and tags, and push the `.gem` file to
40
+ [rubygems.org](https://rubygems.org).
41
+
42
+ Run the specs with:
43
+
44
+ $ bundle exec rspec
45
+
46
+ ## Contributing
47
+
48
+ 1. Fork it ( https://github.com/sunny/currency_by_ip/fork )
49
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
50
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
51
+ 4. Push to the branch (`git push origin my-new-feature`)
52
+ 5. Create a new Pull Request
53
+ 6. Dance
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "currency_by_ip"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
@@ -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 'currency_by_ip/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "currency_by_ip"
8
+ spec.version = CurrencyByIp::VERSION
9
+ spec.authors = ["Sunny Ripert"]
10
+ spec.email = ["sunny@sunfox.org"]
11
+
12
+ spec.summary = %q{Guess the currency from the IP address.}
13
+ spec.description = %q{Returns a currency string thanks to GeoIP's ip database.}
14
+ spec.homepage = "https://github.com/sunny/currency_by_ip"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_runtime_dependency "geoip"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.8"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec"
27
+ end
Binary file
@@ -0,0 +1,256 @@
1
+ module CurrencyByIp
2
+ # ISO2 country codes to country currency codes
3
+ # via http://country.io/data/
4
+ COUNTRY_TO_CURRENCY= {
5
+ "AD" => "EUR",
6
+ "AE" => "AED",
7
+ "AF" => "AFN",
8
+ "AG" => "XCD",
9
+ "AI" => "XCD",
10
+ "AL" => "ALL",
11
+ "AM" => "AMD",
12
+ "AO" => "AOA",
13
+ "AQ" => "",
14
+ "AR" => "ARS",
15
+ "AS" => "USD",
16
+ "AT" => "EUR",
17
+ "AU" => "AUD",
18
+ "AW" => "AWG",
19
+ "AX" => "EUR",
20
+ "AZ" => "AZN",
21
+ "BA" => "BAM",
22
+ "BB" => "BBD",
23
+ "BD" => "BDT",
24
+ "BE" => "EUR",
25
+ "BF" => "XOF",
26
+ "BG" => "BGN",
27
+ "BH" => "BHD",
28
+ "BI" => "BIF",
29
+ "BJ" => "XOF",
30
+ "BL" => "EUR",
31
+ "BM" => "BMD",
32
+ "BN" => "BND",
33
+ "BO" => "BOB",
34
+ "BQ" => "USD",
35
+ "BR" => "BRL",
36
+ "BS" => "BSD",
37
+ "BT" => "BTN",
38
+ "BV" => "NOK",
39
+ "BW" => "BWP",
40
+ "BY" => "BYR",
41
+ "BZ" => "BZD",
42
+ "CA" => "CAD",
43
+ "CC" => "AUD",
44
+ "CD" => "CDF",
45
+ "CF" => "XAF",
46
+ "CG" => "XAF",
47
+ "CH" => "CHF",
48
+ "CI" => "XOF",
49
+ "CK" => "NZD",
50
+ "CL" => "CLP",
51
+ "CM" => "XAF",
52
+ "CN" => "CNY",
53
+ "CO" => "COP",
54
+ "CR" => "CRC",
55
+ "CU" => "CUP",
56
+ "CV" => "CVE",
57
+ "CW" => "ANG",
58
+ "CX" => "AUD",
59
+ "CY" => "EUR",
60
+ "CZ" => "CZK",
61
+ "DE" => "EUR",
62
+ "DJ" => "DJF",
63
+ "DK" => "DKK",
64
+ "DM" => "XCD",
65
+ "DO" => "DOP",
66
+ "DZ" => "DZD",
67
+ "EC" => "USD",
68
+ "EE" => "EUR",
69
+ "EG" => "EGP",
70
+ "EH" => "MAD",
71
+ "ER" => "ERN",
72
+ "ES" => "EUR",
73
+ "ET" => "ETB",
74
+ "FI" => "EUR",
75
+ "FJ" => "FJD",
76
+ "FK" => "FKP",
77
+ "FM" => "USD",
78
+ "FO" => "DKK",
79
+ "FR" => "EUR",
80
+ "GA" => "XAF",
81
+ "GB" => "GBP",
82
+ "GD" => "XCD",
83
+ "GE" => "GEL",
84
+ "GF" => "EUR",
85
+ "GG" => "GBP",
86
+ "GH" => "GHS",
87
+ "GI" => "GIP",
88
+ "GL" => "DKK",
89
+ "GM" => "GMD",
90
+ "GN" => "GNF",
91
+ "GP" => "EUR",
92
+ "GQ" => "XAF",
93
+ "GR" => "EUR",
94
+ "GS" => "GBP",
95
+ "GT" => "GTQ",
96
+ "GU" => "USD",
97
+ "GW" => "XOF",
98
+ "GY" => "GYD",
99
+ "HK" => "HKD",
100
+ "HM" => "AUD",
101
+ "HN" => "HNL",
102
+ "HR" => "HRK",
103
+ "HT" => "HTG",
104
+ "HU" => "HUF",
105
+ "ID" => "IDR",
106
+ "IE" => "EUR",
107
+ "IL" => "ILS",
108
+ "IM" => "GBP",
109
+ "IN" => "INR",
110
+ "IO" => "USD",
111
+ "IQ" => "IQD",
112
+ "IR" => "IRR",
113
+ "IS" => "ISK",
114
+ "IT" => "EUR",
115
+ "JE" => "GBP",
116
+ "JM" => "JMD",
117
+ "JO" => "JOD",
118
+ "JP" => "JPY",
119
+ "KE" => "KES",
120
+ "KG" => "KGS",
121
+ "KH" => "KHR",
122
+ "KI" => "AUD",
123
+ "KM" => "KMF",
124
+ "KN" => "XCD",
125
+ "KP" => "KPW",
126
+ "KR" => "KRW",
127
+ "KW" => "KWD",
128
+ "KY" => "KYD",
129
+ "KZ" => "KZT",
130
+ "LA" => "LAK",
131
+ "LB" => "LBP",
132
+ "LC" => "XCD",
133
+ "LI" => "CHF",
134
+ "LK" => "LKR",
135
+ "LR" => "LRD",
136
+ "LS" => "LSL",
137
+ "LT" => "LTL",
138
+ "LU" => "EUR",
139
+ "LV" => "EUR",
140
+ "LY" => "LYD",
141
+ "MA" => "MAD",
142
+ "MC" => "EUR",
143
+ "MD" => "MDL",
144
+ "ME" => "EUR",
145
+ "MF" => "EUR",
146
+ "MG" => "MGA",
147
+ "MH" => "USD",
148
+ "MK" => "MKD",
149
+ "ML" => "XOF",
150
+ "MM" => "MMK",
151
+ "MN" => "MNT",
152
+ "MO" => "MOP",
153
+ "MP" => "USD",
154
+ "MQ" => "EUR",
155
+ "MR" => "MRO",
156
+ "MS" => "XCD",
157
+ "MT" => "EUR",
158
+ "MU" => "MUR",
159
+ "MV" => "MVR",
160
+ "MW" => "MWK",
161
+ "MX" => "MXN",
162
+ "MY" => "MYR",
163
+ "MZ" => "MZN",
164
+ "NA" => "NAD",
165
+ "NC" => "XPF",
166
+ "NE" => "XOF",
167
+ "NF" => "AUD",
168
+ "NG" => "NGN",
169
+ "NI" => "NIO",
170
+ "NL" => "EUR",
171
+ "NO" => "NOK",
172
+ "NP" => "NPR",
173
+ "NR" => "AUD",
174
+ "NU" => "NZD",
175
+ "NZ" => "NZD",
176
+ "OM" => "OMR",
177
+ "PA" => "PAB",
178
+ "PE" => "PEN",
179
+ "PF" => "XPF",
180
+ "PG" => "PGK",
181
+ "PH" => "PHP",
182
+ "PK" => "PKR",
183
+ "PL" => "PLN",
184
+ "PM" => "EUR",
185
+ "PN" => "NZD",
186
+ "PR" => "USD",
187
+ "PS" => "ILS",
188
+ "PT" => "EUR",
189
+ "PW" => "USD",
190
+ "PY" => "PYG",
191
+ "QA" => "QAR",
192
+ "RE" => "EUR",
193
+ "RO" => "RON",
194
+ "RS" => "RSD",
195
+ "RU" => "RUB",
196
+ "RW" => "RWF",
197
+ "SA" => "SAR",
198
+ "SB" => "SBD",
199
+ "SC" => "SCR",
200
+ "SD" => "SDG",
201
+ "SE" => "SEK",
202
+ "SG" => "SGD",
203
+ "SH" => "SHP",
204
+ "SI" => "EUR",
205
+ "SJ" => "NOK",
206
+ "SK" => "EUR",
207
+ "SL" => "SLL",
208
+ "SM" => "EUR",
209
+ "SN" => "XOF",
210
+ "SO" => "SOS",
211
+ "SR" => "SRD",
212
+ "SS" => "SSP",
213
+ "ST" => "STD",
214
+ "SV" => "USD",
215
+ "SX" => "ANG",
216
+ "SY" => "SYP",
217
+ "SZ" => "SZL",
218
+ "TC" => "USD",
219
+ "TD" => "XAF",
220
+ "TF" => "EUR",
221
+ "TG" => "XOF",
222
+ "TH" => "THB",
223
+ "TJ" => "TJS",
224
+ "TK" => "NZD",
225
+ "TL" => "USD",
226
+ "TM" => "TMT",
227
+ "TN" => "TND",
228
+ "TO" => "TOP",
229
+ "TR" => "TRY",
230
+ "TT" => "TTD",
231
+ "TV" => "AUD",
232
+ "TW" => "TWD",
233
+ "TZ" => "TZS",
234
+ "UA" => "UAH",
235
+ "UG" => "UGX",
236
+ "UM" => "USD",
237
+ "US" => "USD",
238
+ "UY" => "UYU",
239
+ "UZ" => "UZS",
240
+ "VA" => "EUR",
241
+ "VC" => "XCD",
242
+ "VE" => "VEF",
243
+ "VG" => "USD",
244
+ "VI" => "USD",
245
+ "VN" => "VND",
246
+ "VU" => "VUV",
247
+ "WF" => "XPF",
248
+ "WS" => "WST",
249
+ "XK" => "EUR",
250
+ "YE" => "YER",
251
+ "YT" => "EUR",
252
+ "ZA" => "ZAR",
253
+ "ZM" => "ZMK",
254
+ "ZW" => "ZWL",
255
+ }
256
+ end
@@ -0,0 +1,3 @@
1
+ module CurrencyByIp
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,12 @@
1
+ require "currency_by_ip/version"
2
+ require "currency_by_ip/country_to_currency"
3
+
4
+ require "geoip"
5
+
6
+ module CurrencyByIp
7
+ def self.find_by_ip(ip, geoip_data_path: "lib/currency_by_ip/GeoIP.dat")
8
+ geo_ip = GeoIP.new(geoip_data_path)
9
+ country = geo_ip.country(ip)
10
+ COUNTRY_TO_CURRENCY[country.country_code2]
11
+ end
12
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: currency_by_ip
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sunny Ripert
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-06-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: geoip
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.8'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
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
+ description: Returns a currency string thanks to GeoIP's ip database.
70
+ email:
71
+ - sunny@sunfox.org
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - .gitignore
77
+ - .rspec
78
+ - .travis.yml
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - currency_by_ip.gemspec
87
+ - lib/currency_by_ip.rb
88
+ - lib/currency_by_ip/GeoIP.dat
89
+ - lib/currency_by_ip/country_to_currency.rb
90
+ - lib/currency_by_ip/version.rb
91
+ homepage: https://github.com/sunny/currency_by_ip
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.5
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Guess the currency from the IP address.
115
+ test_files: []