xe_client 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: fdaeee0666ddaa0e81f9425aad6e689dd5853570
4
+ data.tar.gz: 7b10ff686963faebee6dbd019c0726e9599c94c4
5
+ SHA512:
6
+ metadata.gz: a7328447e7f2bd6871fbf40f0613a5eb4591b169cc1008ac9fbecdbdbef9d78c84de04d21b3737a07f4686e1359cfc0e770f26aae6ba66293d1247c61c1d2dbe
7
+ data.tar.gz: 50d146942dd556d3606ba348404c70f08b46990e4cecac8596023ff5f7f5ab0820227857f6cbc717e4b71d3c7cb7ddb8df4d7c04af5bb142a208d2a3efd1c31b
data/.envrc ADDED
@@ -0,0 +1 @@
1
+ export PATH=./bin:$PATH
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /spec/config.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ before_install: gem install bundler -v 1.12.5
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ## [0.1.0] - 2016-06-22
6
+ ### Added
7
+ - Add initial working version (`#convert_from`)
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at ramon.tayag@gmail.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in xe_client.gemspec
4
+ gemspec
5
+
6
+ gem "virtus-matchers", github: "g5/virtus-matchers"
7
+ gem "pry"
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Ramon Tayag
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,38 @@
1
+ # XEClient
2
+
3
+ Ruby wrapper for XE's REST API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'xe_client'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install xe_client
20
+
21
+ ## Usage
22
+
23
+ See `spec/functional`.
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on [GitHub](https://github.com/imacchiato/xe_client-ruby). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
34
+
35
+
36
+ ## License
37
+
38
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "xe_client"
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/xe_client.rb ADDED
@@ -0,0 +1,22 @@
1
+ require "xe_client/version"
2
+ require "active_model"
3
+ require "virtus"
4
+ require "httparty"
5
+ require "active_support/core_ext/hash/indifferent_access"
6
+ require "xe_client/indifferent_hash"
7
+ require "xe_client/models/quote"
8
+ require "xe_client/client"
9
+ require "xe_client/requests/base_request"
10
+ require "xe_client/requests/convert_from_request"
11
+ require "xe_client/responses/base_response"
12
+ require "xe_client/responses/convert_from_response"
13
+
14
+ module XEClient
15
+
16
+ def self.new(opts)
17
+ client = Client.new(opts)
18
+ raise ArgumentError, client.errors.full_messages if client.invalid?
19
+ client
20
+ end
21
+
22
+ end
@@ -0,0 +1,31 @@
1
+ module XEClient
2
+ class Client
3
+
4
+ DEFAULT_URL = "https://xecdapi.xe.com"
5
+
6
+ include Virtus.model
7
+ attribute :account_id, String
8
+ attribute :api_key, String
9
+ attribute :url, String, default: DEFAULT_URL
10
+
11
+ include ActiveModel::Validations
12
+ validates :account_id, :api_key, presence: true
13
+
14
+ def convert_from(base_currency, counter_currencies, amount)
15
+ args = default_args.merge(
16
+ base_currency: base_currency,
17
+ counter_currencies: counter_currencies,
18
+ amount: amount,
19
+ )
20
+ raw_response = ConvertFromRequest.(args)
21
+ ConvertFromResponse.new(raw_response: raw_response)
22
+ end
23
+
24
+ private
25
+
26
+ def default_args
27
+ attributes.slice(:account_id, :api_key, :url)
28
+ end
29
+
30
+ end
31
+ end
@@ -0,0 +1,7 @@
1
+ module XEClient
2
+ class IndifferentHash < Virtus::Attribute
3
+ def coerce(value)
4
+ value.is_a?(::Hash) ? value.with_indifferent_access : value
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,9 @@
1
+ module XEClient
2
+ class Quote
3
+
4
+ include Virtus.model
5
+ attribute :quotecurrency, String
6
+ attribute :mid, Float
7
+
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ module XEClient
2
+ class BaseRequest
3
+
4
+ include Virtus.model
5
+ attribute :account_id, String
6
+ attribute :api_key, String
7
+ attribute :url, String
8
+
9
+ include ActiveModel::Validations
10
+ validates :account_id, :api_key, :url, presence: true
11
+
12
+ def self.call(opts)
13
+ self.new(opts).call
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,38 @@
1
+ module XEClient
2
+ class ConvertFromRequest < BaseRequest
3
+
4
+ DEFAULT_PATH = "/v1/convert_from.json"
5
+ attribute :base_currency, String
6
+ attribute :counter_currencies, Array[String]
7
+ attribute :amount, Float
8
+ attribute :endpoint, String, lazy: true, default: :default_endpoint
9
+
10
+ validates(
11
+ :base_currency,
12
+ :counter_currencies,
13
+ :amount,
14
+ presence: true,
15
+ )
16
+
17
+ def call
18
+ HTTParty.get(
19
+ endpoint,
20
+ query: {
21
+ from: base_currency,
22
+ to: counter_currencies.join(","),
23
+ amount: amount,
24
+ },
25
+ basic_auth: { username: account_id, password: api_key },
26
+ )
27
+ end
28
+
29
+ private
30
+
31
+ def default_endpoint
32
+ uri = URI.parse(url)
33
+ uri.path = DEFAULT_PATH
34
+ uri.to_s
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,7 @@
1
+ module XEClient
2
+ class BaseResponse
3
+
4
+ include Virtus.model
5
+
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ module XEClient
2
+ class ConvertFromResponse < BaseResponse
3
+
4
+ attribute :from, String, lazy: true, default: :default_from
5
+ attribute :to, Array, lazy: true, default: :default_to
6
+ attribute :raw_response, IndifferentHash
7
+
8
+ private
9
+
10
+ def default_from
11
+ raw_response[:from]
12
+ end
13
+
14
+ def default_to
15
+ raw_response[:to].map do |quote_hash|
16
+ Quote.new(quote_hash)
17
+ end
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module XEClient
2
+ VERSION = "0.1.0"
3
+ end
data/xe_client.gemspec ADDED
@@ -0,0 +1,40 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'xe_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "xe_client"
8
+ spec.version = XEClient::VERSION
9
+ spec.authors = ["Ramon Tayag"]
10
+ spec.email = ["ramon.tayag@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper for XE's REST API}
13
+ spec.homepage = "https://github.com/imacchiato/xe_client-ruby"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
20
+ else
21
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
22
+ end
23
+
24
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
+ spec.bindir = "exe"
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ["lib"]
28
+
29
+ spec.add_dependency "activesupport", ">= 3.0"
30
+ spec.add_dependency "activemodel", ">= 3.0"
31
+ spec.add_dependency "virtus", "~> 1.0"
32
+ spec.add_dependency "httparty"
33
+
34
+ spec.add_development_dependency "bundler", "~> 1.12"
35
+ spec.add_development_dependency "rake", "~> 10.0"
36
+ spec.add_development_dependency "rspec", "~> 3.0"
37
+ spec.add_development_dependency "shoulda-matchers", "~> 3.0"
38
+ spec.add_development_dependency "vcr", "~> 3.0"
39
+ spec.add_development_dependency "webmock", "~> 2.0"
40
+ end
metadata ADDED
@@ -0,0 +1,207 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: xe_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Ramon Tayag
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-22 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activemodel
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: virtus
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: httparty
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.12'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.12'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: shoulda-matchers
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: vcr
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '3.0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '3.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: webmock
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '2.0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '2.0'
153
+ description:
154
+ email:
155
+ - ramon.tayag@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".envrc"
161
+ - ".gitignore"
162
+ - ".rspec"
163
+ - ".travis.yml"
164
+ - CHANGELOG.md
165
+ - CODE_OF_CONDUCT.md
166
+ - Gemfile
167
+ - LICENSE.txt
168
+ - README.md
169
+ - Rakefile
170
+ - bin/console
171
+ - bin/setup
172
+ - lib/xe_client.rb
173
+ - lib/xe_client/client.rb
174
+ - lib/xe_client/indifferent_hash.rb
175
+ - lib/xe_client/models/quote.rb
176
+ - lib/xe_client/requests/base_request.rb
177
+ - lib/xe_client/requests/convert_from_request.rb
178
+ - lib/xe_client/responses/base_response.rb
179
+ - lib/xe_client/responses/convert_from_response.rb
180
+ - lib/xe_client/version.rb
181
+ - xe_client.gemspec
182
+ homepage: https://github.com/imacchiato/xe_client-ruby
183
+ licenses:
184
+ - MIT
185
+ metadata:
186
+ allowed_push_host: https://rubygems.org
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ required_rubygems_version: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - ">="
199
+ - !ruby/object:Gem::Version
200
+ version: '0'
201
+ requirements: []
202
+ rubyforge_project:
203
+ rubygems_version: 2.5.1
204
+ signing_key:
205
+ specification_version: 4
206
+ summary: Ruby wrapper for XE's REST API
207
+ test_files: []