geo_ppp 0.1.4 → 0.1.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2597eeb4b44aea702a71741374dff570adf042a3a7f3887e51fc2cd38decb2b7
4
- data.tar.gz: cccd7bcc8a6b0d94e1e57eb42ac537c21ff4d832161e99bc84ae66a927b59f66
3
+ metadata.gz: 11aca1821df7a6983f1bde1f3280cf79c9992cda2d0e5969a7d9974b8563c704
4
+ data.tar.gz: '0972f1da32af3b6d6c0f79429f5684d245e0d5308a1fe3813837bedbc8d6123f'
5
5
  SHA512:
6
- metadata.gz: '00558f17d0aacc6bb4c5ba2296a76e4018ae4a941f9ed106ed2bdac5ab295e40773e9144df9be8b8afd9c8a07059053959603983489a608c11326462a54536b0'
7
- data.tar.gz: f86da527a35b8cc53f80a2e44bb4bacf1a3602cb63e818c0bffd3a641ed0632803b161ea534a0b0364cab71c6ddd155610a979592be3bc4c2bbb1dabd51bdcb9
6
+ metadata.gz: 93b74ef9317a47a14cfc5a7e1d5caa3f5bb1f2810c1c66c0130ae2391be3745a0ec4f5c70fdd716b86b2edc6a9432fb5b5445a7eade62fee47ca4f2ed51db29b
7
+ data.tar.gz: a643c92d4b2ebc8cc4312ecc06953183fd5a98ccebff8b1b4414a93acfce453d06ca3175cd35db474ccef5a81f613fce9597f4fe44d90caa25b03d30526df40b
data/README.md CHANGED
@@ -1,34 +1,58 @@
1
- # GeoPpp
1
+ # Geo Purchasing Power Parity
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
4
-
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/geo_ppp`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Sell your digital products at purchasing power parity for based on users country. Not everyone is able to pay for the default pricing of the high income world. Cup of Coffee in Colombia or Indonesia cost less than USA or Australia, apply same principal to your digital products and get more customers. This package is inspired by `purchasing-power-parity` npm and uses their API.
6
4
 
7
5
  ## Installation
8
6
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
- Install the gem and add to the application's Gemfile by executing:
7
+ Add this line to your application's Gemfile
8
+ ```bash
9
+ gem 'geo_ppp'
10
+ ```
12
11
 
12
+ and run bundle
13
13
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+ bundle install
15
15
  ```
16
16
 
17
17
  If bundler is not being used to manage dependencies, install the gem by executing:
18
18
 
19
19
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
20
+ gem install geo_pp
21
21
  ```
22
22
 
23
23
  ## Usage
24
24
 
25
- TODO: Write usage instructions here
25
+ ```ruby
26
+ GeoPPPFetcher.fetch
27
+ ```
28
+ will get the purchasing power parity data based on user's IP address.
29
+
30
+ ```ruby
31
+ GeoPPPFetcher.fetch('LK')
32
+ ```
33
+ will get the purchasing power parity data based on country code provided.
26
34
 
27
- ## Development
35
+ Both above will return a following json structure, you could use ```pppConversionFactor``` to convert it price based on user's geographic location
28
36
 
29
- After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
37
+ ```ruby
38
+ {"countryCodeIsoAlpha2":"LK","countryCodeIsoAlpha3":"LKA","currenciesCountry":{"LKR":{"symbol":"Rs රු","name":"Sri Lankan rupee"}},"currencyMain":{"exchangeRate":300.701498,"name":"USD","symbol":"$"},"ppp":10040.0,"pppConversionFactor":0.33}
39
+ ```
40
+
41
+ ```ruby
42
+ def index
43
+ original_price = 79.99
44
+
45
+ begin
46
+ response = GeoPPPFetcher.fetch
47
+ discounted_price = original_price * response['pppConversionFactor']
48
+ data = { original_price: original_price, discounted_price: discounted_price }
49
+ render json: { success: true, data: data }
50
+ rescue StandardError => e
51
+ render json: { success: false, error: e.message }, status: :unprocessable_entity
52
+ end
53
+ end
54
+ ```
30
55
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
56
 
33
57
  ## Contributing
34
58
 
@@ -40,4 +64,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
40
64
 
41
65
  ## Code of Conduct
42
66
 
43
- Everyone interacting in the GeoPpp project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/geo_ppp/blob/master/CODE_OF_CONDUCT.md).
67
+ Everyone interacting in the geo_ppp project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/geo_ppp/blob/master/CODE_OF_CONDUCT.md).
@@ -3,11 +3,16 @@ require 'json'
3
3
 
4
4
  class GeoPPPFetcher
5
5
  GEO_API_URL = 'https://freegeoip.app/json/'.freeze
6
- PPP_API_URL = 'https://api.purchasing-power-parity.com/?target='.freeze
7
-
8
- def self.fetch
9
- geo = fetch_geo
10
- fetch_ppp(geo)
6
+ # https://api.purchasing-power-parity.com/?target=ID redirects to https://ppp-api.fly.dev/?target=ID and then results are returned
7
+ PPP_API_URL = 'https://ppp-api.fly.dev/?target='.freeze
8
+
9
+ def self.fetch(country_code = nil)
10
+ geo = if country_code.nil?
11
+ fetch_geo
12
+ else
13
+ { 'country_code' => country_code }
14
+ end
15
+ fetch_ppp(geo)
11
16
  end
12
17
 
13
18
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GeoPpp
4
- VERSION = "0.1.4"
4
+ VERSION = "0.1.6"
5
5
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: geo_ppp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - waruna
8
8
  bindir: exe
9
9
  cert_chain: []
10
- date: 2025-01-09 00:00:00.000000000 Z
10
+ date: 2025-01-24 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: A Ruby library to fetch PPP based on user's geolocation using freegeoip.com
13
13
  and purchasing-power-parity.com APIs.