exnify 1.0.0

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,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 3394d2d870651b3fcb04c1037df365f7e1c64ac41b7a04e97aae7f548831e181
4
+ data.tar.gz: c8aed6bff826940d571600c1e5798ecdae72253092eabdec7ffa837aabc82c8b
5
+ SHA512:
6
+ metadata.gz: 44f4780a4d3cfc29f44fc8028fc7ca992677a1786d32e713a5a8b2a8af72c6d37101161dd2aea85865fb41677b25cc142158e22e89f71b1fc403a8781df269d8
7
+ data.tar.gz: 7fd5ba2d07ae98c77e7f655aa6f1a54869971c91cedbe05638cc6caeba69a30500890480bbdeb8221ed0815789c180df3cefa8f5ae303acf60b849972d219e49
data/README.md ADDED
@@ -0,0 +1,25 @@
1
+ # Exnify Ruby SDK
2
+
3
+ Official Ruby gem for the [Exnify](https://exnify.com) currency API.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ gem install exnify
9
+ ```
10
+
11
+ Or add to your Gemfile:
12
+
13
+ ```ruby
14
+ gem "exnify"
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```ruby
20
+ require "exnify"
21
+
22
+ client = Exnify::Client.new("YOUR_API_KEY")
23
+ rates = client.latest(base: "USD")
24
+ puts rates["data"]
25
+ ```
@@ -0,0 +1,77 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module Exnify
6
+ HISTORY_RANGES = %w[1d 7d 30d 1y 5y 10y].freeze
7
+
8
+ class Client
9
+ DEFAULT_BASE_URL = "https://api.exnify.com"
10
+
11
+ def initialize(api_key, base_url: DEFAULT_BASE_URL)
12
+ @api_key = api_key
13
+ @base_url = base_url.to_s.chomp("/")
14
+ end
15
+
16
+ def status
17
+ request("/v1/status")
18
+ end
19
+
20
+ def currencies
21
+ request("/v1/currencies")
22
+ end
23
+
24
+ def symbols
25
+ currencies
26
+ end
27
+
28
+ def latest(base: nil)
29
+ params = {}
30
+ params[:base] = base if base
31
+ request("/v1/latest", params)
32
+ end
33
+
34
+ def popular
35
+ request("/v1/popular")
36
+ end
37
+
38
+ def convert(from:, to:, amount:)
39
+ request("/v1/convert", { from: from, to: to, amount: amount })
40
+ end
41
+
42
+ def history(from:, to:, start:, end_date:)
43
+ request("/v1/history", { from: from, to: to, start: start, end: end_date })
44
+ end
45
+
46
+ def history_range(from:, to:, range:)
47
+ request("/v1/history/range", { from: from, to: to, range: range })
48
+ end
49
+
50
+ private
51
+
52
+ def request(path, params = {})
53
+ uri = URI.parse("#{@base_url}#{path}")
54
+ uri.query = URI.encode_www_form(params) unless params.empty?
55
+
56
+ http = Net::HTTP.new(uri.host, uri.port)
57
+ http.use_ssl = uri.scheme == "https"
58
+
59
+ req = Net::HTTP::Get.new(uri)
60
+ req["X-Api-Key"] = @api_key
61
+
62
+ res = http.request(req)
63
+ body = JSON.parse(res.body)
64
+
65
+ unless res.is_a?(Net::HTTPSuccess) && body["success"]
66
+ error = body["error"] || {}
67
+ raise Error.new(
68
+ error["message"] || "Request failed with status #{res.code}",
69
+ status: res.code.to_i,
70
+ code: error["code"]
71
+ )
72
+ end
73
+
74
+ body
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,11 @@
1
+ module Exnify
2
+ class Error < StandardError
3
+ attr_reader :status, :code
4
+
5
+ def initialize(message, status: 0, code: nil)
6
+ super(message)
7
+ @status = status
8
+ @code = code
9
+ end
10
+ end
11
+ end
data/lib/exnify.rb ADDED
@@ -0,0 +1,5 @@
1
+ require_relative "exnify/error"
2
+ require_relative "exnify/client"
3
+
4
+ module Exnify
5
+ end
metadata ADDED
@@ -0,0 +1,44 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exnify
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Exnify
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: Ruby SDK for Exnify exchange rates, conversion, and historical data.
13
+ email:
14
+ - support@exnify.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - README.md
20
+ - lib/exnify.rb
21
+ - lib/exnify/client.rb
22
+ - lib/exnify/error.rb
23
+ homepage: https://exnify.com
24
+ licenses:
25
+ - MIT
26
+ metadata: {}
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 2.7.0
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubygems_version: 4.0.10
42
+ specification_version: 4
43
+ summary: Official Ruby client for the Exnify currency API
44
+ test_files: []