questrade_client 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,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 366a59daa972a8ef598f95be3ef864df3e81526e
4
+ data.tar.gz: 775d3d26147bf9e72c9c7655f6ee33ea707f6e69
5
+ SHA512:
6
+ metadata.gz: 984ff575b495ea46f623f5054231a3ba94e8fd609db0d7b06b0803603c6ebe78c1932bea35cd977c61cc2f2f12e654fce29e0c639bdd089b8d09dd14d8a4bf58
7
+ data.tar.gz: 8eec74ff12d70bee1a10cc20743e77a38a6e8c80307e85462e8177e0e6528f9c70f496c668f07fe168ef2f70eab3f7b61b76c254eb89c479263a35a3bd4ebb4f
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,3 @@
1
+ --color
2
+ --order random
3
+ --format documentation
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ sudo: false
3
+ rvm:
4
+ - 2.1.8
5
+ - 2.2.4
6
+ - 2.3.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in questrade_client.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Shopify
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,52 @@
1
+ # QuestradeClient
2
+
3
+ Set up a practice account to play around:
4
+
5
+ http://www.questrade.com/api/free-practice-account
6
+
7
+ Login with it at:
8
+
9
+ https://practicelogin.questrade.com/Signin.aspx?ReturnUrl=%2fAPIAccess%2fUserApps.aspx
10
+
11
+ Register a practice app (give it all permissions, this is a test account)
12
+
13
+ Generate a new device authorization token, you'll need that! It's considered a "refresh" token. After being used once, it's no more good - you'll get a new refresh token though.
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'questrade_client'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ $ bundle
26
+
27
+ Or install it yourself as:
28
+
29
+ $ gem install questrade_client
30
+
31
+ ## Usage
32
+
33
+ TODO: Write usage instructions here
34
+
35
+ ## Development
36
+
37
+ 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.
38
+
39
+ 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).
40
+
41
+ ## Contributing
42
+
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/questrade_client.
44
+
45
+
46
+ ## License
47
+
48
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
49
+
50
+ # Disclaimer
51
+
52
+ This gem is NOT supported, it is not affiliated with questrade in any way. Use at your own risk. Test all operations in a sandbox before executing them with a real account and real money. Don't be an idiot.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler/gem_tasks'
2
+ begin
3
+ require 'rspec/core/rake_task'
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ rescue LoadError
6
+ end
7
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'questrade_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/rspec ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rspec' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rspec-core", "rspec")
data/bin/rubocop ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This file was generated by Bundler.
4
+ #
5
+ # The application 'rubocop' is installed as part of a gem, and
6
+ # this file is here to facilitate running it.
7
+ #
8
+
9
+ require "pathname"
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
11
+ Pathname.new(__FILE__).realpath)
12
+
13
+ require "rubygems"
14
+ require "bundler/setup"
15
+
16
+ load Gem.bin_path("rubocop", "rubocop")
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
@@ -0,0 +1,6 @@
1
+ require 'questrade_client/version'
2
+ require 'questrade_client/client'
3
+
4
+ module QuestradeClient
5
+ USER_AGENT = "questrade_client/#{QuestradeClient::VERSION}".freeze
6
+ end
Binary file
@@ -0,0 +1,15 @@
1
+ module QuestradeClient
2
+ module Account
3
+ # Retrieves current server time.
4
+ #
5
+ # Docs: http://www.questrade.com/api/documentation/rest-operations/account-calls/time
6
+ #
7
+ # @return [DateTime] Current server time in ISO format and Eastern time zone.
8
+ # @example
9
+ # client.time
10
+ def time
11
+ DateTime.parse(get('/time')['time'])
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,86 @@
1
+ require 'questrade_client/account'
2
+ require 'faraday_middleware'
3
+
4
+ module QuestradeClient
5
+
6
+ def self.login(refresh_token, practice = false)
7
+ url = if practice
8
+ "https://practicelogin.questrade.com/oauth2/"
9
+ else
10
+ "https://login.questrade.com/oauth2/"
11
+ end
12
+
13
+ conn = Faraday.new @endpoint do |f|
14
+ f.headers[:user_agent] = QuestradeClient::USER_AGENT
15
+ f.headers['Content-length'] = '0'
16
+ f.response :json, content_type: /\bjson$/
17
+ f.adapter Faraday.default_adapter
18
+ end
19
+ endpoint = "#{url}token?grant_type=refresh_token&refresh_token=#{refresh_token}"
20
+ r = conn.send(:post, endpoint)
21
+
22
+ if r.success?
23
+ # puts "New refresh token: #{r.body['refresh_token']}"
24
+ endpoint = r.body['api_server']
25
+ token = r.body['access_token']
26
+ return Client.new(endpoint: endpoint, token: token)
27
+ else
28
+ # puts "Login failed!"
29
+ # puts r.body
30
+ return nil
31
+ end
32
+ end
33
+
34
+ class Client
35
+ attr_reader :endpoint, :token
36
+
37
+ def initialize(options = {})
38
+ @endpoint = options[:endpoint].to_s
39
+ @token = options[:token].to_s
40
+ raise ArgumentError, ":endpoint can't be blank" if @endpoint.empty?
41
+ raise ArgumentError, ":token can't be blank" if @token.empty?
42
+ end
43
+
44
+ include QuestradeClient::Account
45
+
46
+ private
47
+
48
+ def get(path, options = {})
49
+ request(:get, path, options)
50
+ end
51
+
52
+ def post(path, data = {})
53
+ request(:post, path, data)
54
+ end
55
+
56
+ def put(path, data = {})
57
+ request(:put, path, data)
58
+ end
59
+
60
+ def request(method, path, data = {})
61
+ res = connection.send(method, "v1/#{path}", data)
62
+ if res.success? && !res.body.nil? && !res.body.empty? && res.body != ' '
63
+ res.body
64
+ else
65
+ res
66
+ end
67
+ end
68
+
69
+ # Returns a Faraday::Connection object
70
+ #
71
+ # @return [Faraday::Connection]
72
+ def connection
73
+ @connection ||= Faraday.new @endpoint do |f|
74
+ f.request :json
75
+ f.headers[:user_agent] = QuestradeClient::USER_AGENT
76
+ f.headers['Authorization'] = "Bearer #{@token}"
77
+
78
+ # f.response :logger
79
+ f.response :mashify
80
+ f.response :json, content_type: /\bjson$/
81
+
82
+ f.adapter Faraday.default_adapter
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ module QuestradeClient
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'questrade_client/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'questrade_client'
8
+ spec.version = QuestradeClient::VERSION
9
+ spec.authors = ['Dale Hamel']
10
+ spec.email = ['daleha@gmail.com']
11
+
12
+ spec.summary = 'Ruby client library for the Questrade API'
13
+ spec.homepage = 'https://github.com/dalehamel/questrade_client'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'exe'
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_development_dependency 'bundler', '~> 1.11'
22
+ spec.add_development_dependency 'rake'
23
+ spec.add_development_dependency 'rspec', '~> 3.0'
24
+ spec.add_development_dependency 'webmock', '~> 1.21.0'
25
+ spec.add_development_dependency 'pry'
26
+ spec.add_development_dependency 'rubocop', '~> 0.39.0'
27
+ spec.add_development_dependency 'simplecov', ['=0.10.0']
28
+
29
+ spec.add_dependency 'faraday', '~> 0.9.0'
30
+ spec.add_dependency 'faraday_middleware', '~> 0.9.0'
31
+ spec.add_dependency 'hashie', '~> 3.0'
32
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: questrade_client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dale Hamel
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.21.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.21.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.39.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.39.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '='
102
+ - !ruby/object:Gem::Version
103
+ version: 0.10.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '='
109
+ - !ruby/object:Gem::Version
110
+ version: 0.10.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: faraday
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.9.0
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.9.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: faraday_middleware
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.9.0
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.9.0
139
+ - !ruby/object:Gem::Dependency
140
+ name: hashie
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '3.0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '3.0'
153
+ description:
154
+ email:
155
+ - daleha@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - bin/console
168
+ - bin/rspec
169
+ - bin/rubocop
170
+ - bin/setup
171
+ - lib/questrade_client.rb
172
+ - lib/questrade_client/.client.rb.swp
173
+ - lib/questrade_client/account.rb
174
+ - lib/questrade_client/client.rb
175
+ - lib/questrade_client/version.rb
176
+ - questrade_client.gemspec
177
+ homepage: https://github.com/dalehamel/questrade_client
178
+ licenses:
179
+ - MIT
180
+ metadata: {}
181
+ post_install_message:
182
+ rdoc_options: []
183
+ require_paths:
184
+ - lib
185
+ required_ruby_version: !ruby/object:Gem::Requirement
186
+ requirements:
187
+ - - ">="
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ required_rubygems_version: !ruby/object:Gem::Requirement
191
+ requirements:
192
+ - - ">="
193
+ - !ruby/object:Gem::Version
194
+ version: '0'
195
+ requirements: []
196
+ rubyforge_project:
197
+ rubygems_version: 2.5.1
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: Ruby client library for the Questrade API
201
+ test_files: []