empireavenue 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.md +44 -0
- data/README.md +30 -0
- data/Rakefile +8 -0
- data/empireavenue.gemspec +27 -0
- data/lib/empireavenue/action/buy_group_spec.rb +31 -0
- data/lib/empireavenue/api/arguments.rb +13 -0
- data/lib/empireavenue/api/portfolio_base.rb +13 -0
- data/lib/empireavenue/api/portfolio_get.rb +13 -0
- data/lib/empireavenue/api/profile_bank_balance.rb +9 -0
- data/lib/empireavenue/api/profile_info.rb +11 -0
- data/lib/empireavenue/api/profile_shareholders.rb +13 -0
- data/lib/empireavenue/api/search_recent.rb +9 -0
- data/lib/empireavenue/api/shares_buy.rb +11 -0
- data/lib/empireavenue/api/shares_sell.rb +11 -0
- data/lib/empireavenue/base.rb +126 -0
- data/lib/empireavenue/basic_user.rb +10 -0
- data/lib/empireavenue/client.rb +89 -0
- data/lib/empireavenue/configurable.rb +84 -0
- data/lib/empireavenue/default.rb +97 -0
- data/lib/empireavenue/entity.rb +7 -0
- data/lib/empireavenue/error/client_error.rb +35 -0
- data/lib/empireavenue/error/configuration_error.rb +8 -0
- data/lib/empireavenue/error/decode_error.rb +9 -0
- data/lib/empireavenue/error/forbidden.rb +10 -0
- data/lib/empireavenue/error/identity_map_key_error.rb +9 -0
- data/lib/empireavenue/error/internal_server_error.rb +11 -0
- data/lib/empireavenue/error/not_found.rb +10 -0
- data/lib/empireavenue/error/server_error.rb +28 -0
- data/lib/empireavenue/error/service_unavailable.rb +11 -0
- data/lib/empireavenue/error.rb +33 -0
- data/lib/empireavenue/identity.rb +51 -0
- data/lib/empireavenue/identity_map.rb +22 -0
- data/lib/empireavenue/response/parse_json.rb +22 -0
- data/lib/empireavenue/response/raise_error.rb +31 -0
- data/lib/empireavenue/user.rb +9 -0
- data/lib/empireavenue/version.rb +18 -0
- data/lib/empireavenue.rb +32 -0
- data/spec/empireavenue/api/portfolio/portfolio_base_spec.rb +49 -0
- data/spec/empireavenue/api/portfolio/portfolio_base_spec.rb~ +49 -0
- data/spec/empireavenue/api/portfolio/portfolio_get_spec.rb +49 -0
- data/spec/empireavenue/api/portfolio/portfolio_get_spec.rb~ +39 -0
- data/spec/empireavenue/api/profile/profile_bank_balance_spec.rb +18 -0
- data/spec/empireavenue/api/profile/profile_bank_balance_spec.rb~ +18 -0
- data/spec/empireavenue/api/profile/profile_info_spec.rb +38 -0
- data/spec/empireavenue/api/profile/profile_info_spec.rb~ +40 -0
- data/spec/empireavenue/api/profile/profile_shareholders_spec.rb +50 -0
- data/spec/empireavenue/api/profile/profile_shareholders_spec.rb~ +50 -0
- data/spec/empireavenue/api/search/search_recent_spec.rb +16 -0
- data/spec/empireavenue/api/search/search_recent_spec.rb~ +16 -0
- data/spec/empireavenue/api/shares/shares_buy_spec.rb +31 -0
- data/spec/empireavenue/api/shares/shares_buy_spec.rb~ +30 -0
- data/spec/empireavenue/api/shares/shares_sell_spec.rb +31 -0
- data/spec/empireavenue/api/shares/shares_sell_spec.rb~ +31 -0
- data/spec/empireavenue/base_spec.rb +111 -0
- data/spec/empireavenue/basic_user_spec.rb +23 -0
- data/spec/empireavenue/basic_user_spec.rb~ +23 -0
- data/spec/empireavenue/client_spec.rb +149 -0
- data/spec/empireavenue/client_spec.rb~ +149 -0
- data/spec/empireavenue/error/client_error_spec.rb +27 -0
- data/spec/empireavenue/error/client_error_spec.rb~ +27 -0
- data/spec/empireavenue/error/server_error_spec.rb +20 -0
- data/spec/empireavenue/error/server_error_spec.rb~ +20 -0
- data/spec/empireavenue/error_spec.rb +20 -0
- data/spec/empireavenue/error_spec.rb~ +20 -0
- data/spec/empireavenue/identifiable_spec.rb +50 -0
- data/spec/empireavenue/identifiable_spec.rb~ +50 -0
- data/spec/factory_classes.rb +137 -0
- data/spec/factory_classes.rb~ +137 -0
- data/spec/helper.rb +53 -0
- data/spec/helper.rb~ +51 -0
- metadata +219 -0
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'empireavenue/error'
|
2
|
+
|
3
|
+
module EmpireAvenue
|
4
|
+
class Error
|
5
|
+
# Raised when EmpireAvenue returns a 4xx HTTP status code or there's an error in Faraday
|
6
|
+
class ClientError < EmpireAvenue::Error
|
7
|
+
|
8
|
+
# Create a new error from an HTTP environment
|
9
|
+
#
|
10
|
+
# @param response [Hash]
|
11
|
+
# @return [EmpireAvenue::Error]
|
12
|
+
def self.from_response(response={})
|
13
|
+
new(parse_error(response[:body]), response[:response_headers])
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def self.parse_error(body)
|
19
|
+
if body.nil?
|
20
|
+
''
|
21
|
+
elsif body[:error]
|
22
|
+
body[:error]
|
23
|
+
elsif body[:errors]
|
24
|
+
first = Array(body[:errors]).first
|
25
|
+
if first.kind_of?(Hash)
|
26
|
+
first[:message].chomp
|
27
|
+
else
|
28
|
+
first.chomp
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'empireavenue/error/server_error'
|
2
|
+
|
3
|
+
module EmpireAvenue
|
4
|
+
class Error
|
5
|
+
# Raised when EmpireAvenue returns the HTTP status code 500
|
6
|
+
class InternalServerError < EmpireAvenue::Error::ServerError
|
7
|
+
HTTP_STATUS_CODE = 500
|
8
|
+
MESSAGE = "Something is technically wrong."
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'empireavenue/error'
|
2
|
+
|
3
|
+
module EmpireAvenue
|
4
|
+
class Error
|
5
|
+
# Raised when EmpireAvenue returns a 5xx HTTP status code
|
6
|
+
class ServerError < EmpireAvenue::Error
|
7
|
+
MESSAGE = "Server Error"
|
8
|
+
|
9
|
+
# Create a new error from an HTTP environment
|
10
|
+
#
|
11
|
+
# @param response [Hash]
|
12
|
+
# @return [EmpireAvenue::Error]
|
13
|
+
def self.from_response(response={})
|
14
|
+
new(nil, response[:response_headers])
|
15
|
+
end
|
16
|
+
|
17
|
+
# Initializes a new ServerError object
|
18
|
+
#
|
19
|
+
# @param message [String]
|
20
|
+
# @param response_headers [Hash]
|
21
|
+
# @return [EmpireAvenue::Error::ServerError]
|
22
|
+
def initialize(message=nil, response_headers={})
|
23
|
+
super((message || self.class.const_get(:MESSAGE)), response_headers)
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'empireavenue/error/server_error'
|
2
|
+
|
3
|
+
module EmpireAvenue
|
4
|
+
class Error
|
5
|
+
# Raised when EmpireAvenue returns the HTTP status code 503
|
6
|
+
class ServiceUnavailable < EmpireAvenue::Error::ServerError
|
7
|
+
HTTP_STATUS_CODE = 503
|
8
|
+
MESSAGE = "(__-){ EmpireAvenue is over capacity."
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module EmpireAvenue
|
2
|
+
# customer error class for any errors
|
3
|
+
class Error < StandardError
|
4
|
+
attr_reader :wrapped_exception
|
5
|
+
|
6
|
+
# @return [Hash]
|
7
|
+
def self.errors
|
8
|
+
@errors ||= Hash[descendants.map{|klass| [klass.const_get(:HTTP_STATUS_CODE), klass]}]
|
9
|
+
end
|
10
|
+
|
11
|
+
# @return [Array]
|
12
|
+
def self.descendants
|
13
|
+
ObjectSpace.each_object(::Class).select{|klass| klass < self}
|
14
|
+
end
|
15
|
+
|
16
|
+
# Initializes a new Error object
|
17
|
+
#
|
18
|
+
# @param exception [Exception, String]
|
19
|
+
# @param response_headers [Hash]
|
20
|
+
# @return [EmpireAvenue::Error]
|
21
|
+
def initialize(exception=$!, response_headers={})
|
22
|
+
#@rate_limit = EmpireAvenue::RateLimit.new(response_headers)
|
23
|
+
@wrapped_exception = exception
|
24
|
+
exception.respond_to?(:backtrace) ? super(exception.message) : super(exception.to_s)
|
25
|
+
end
|
26
|
+
|
27
|
+
def backtrace
|
28
|
+
@wrapped_exception.respond_to?(:backtrace) ? @wrapped_exception.backtrace : super
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'empireavenue/base'
|
2
|
+
require 'empireavenue/error/identity_map_key_error'
|
3
|
+
|
4
|
+
module EmpireAvenue
|
5
|
+
class Identity < EmpireAvenue::Base
|
6
|
+
|
7
|
+
def self.fetch(attrs)
|
8
|
+
return unless identity_map
|
9
|
+
|
10
|
+
id = attrs[:id]
|
11
|
+
if id && object = identity_map.fetch(id)
|
12
|
+
return object.update(attrs)
|
13
|
+
end
|
14
|
+
|
15
|
+
return yield if block_given?
|
16
|
+
raise EmpireAvenue::Error::IdentityMapKeyError, "key not found"
|
17
|
+
end
|
18
|
+
|
19
|
+
# Stores an object in the identity map.
|
20
|
+
#
|
21
|
+
# @param object [Object]
|
22
|
+
# @return [EmpireAvenue::Identity]
|
23
|
+
def self.store(object)
|
24
|
+
return object unless identity_map
|
25
|
+
identity_map.store(object.id, object)
|
26
|
+
end
|
27
|
+
|
28
|
+
# Initializes a new object
|
29
|
+
#
|
30
|
+
# @param attrs [Hash]
|
31
|
+
# @raise [ArgumentError] Error raised when supplied argument is missing an :id key.
|
32
|
+
# @return [EmpireAvenue::Identity]
|
33
|
+
def initialize(attrs={})
|
34
|
+
attrs[:id] = attrs[:ticker] unless attrs[:id]
|
35
|
+
super
|
36
|
+
raise ArgumentError, "argument must have an :id key" unless id
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param other [EmpireAvenue::Identity]
|
40
|
+
# @return [Boolean]
|
41
|
+
def ==(other)
|
42
|
+
super || attr_equal(:id, other) || attrs_equal(other)
|
43
|
+
end
|
44
|
+
|
45
|
+
# @return [Integer]
|
46
|
+
def id
|
47
|
+
@attrs[:id]
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module EmpireAvenue
|
2
|
+
|
3
|
+
# Tracks objects to help ensure that each object gets loaded only once.
|
4
|
+
# See: http://www.martinfowler.com/eaaCatalog/identityMap.html
|
5
|
+
class IdentityMap < Hash
|
6
|
+
|
7
|
+
# @param id
|
8
|
+
# @return [Object]
|
9
|
+
def fetch(id)
|
10
|
+
self[id]
|
11
|
+
end
|
12
|
+
|
13
|
+
# @param id
|
14
|
+
# @param object
|
15
|
+
# @return [Object]
|
16
|
+
def store(id, object)
|
17
|
+
self[id] = object
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module EmpireAvenue
|
2
|
+
module Response
|
3
|
+
class ParseJson < Faraday::Response::Middleware
|
4
|
+
|
5
|
+
def parse(body)
|
6
|
+
case body
|
7
|
+
when /\A^\s*$\z/, nil
|
8
|
+
nil
|
9
|
+
else
|
10
|
+
MultiJson.decode(body, :symbolize_keys => true)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def on_complete(env)
|
15
|
+
if respond_to?(:parse)
|
16
|
+
env[:body] = parse(env[:body]) unless [204, 301, 302, 304].include?(env[:status])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
#require 'empireavenue/error/bad_gateway'
|
3
|
+
#require 'empireavenue/error/bad_request'
|
4
|
+
require 'empireavenue/error/forbidden'
|
5
|
+
#require 'empireavenue/error/gateway_timeout'
|
6
|
+
require 'empireavenue/error/internal_server_error'
|
7
|
+
#require 'empireavenue/error/not_acceptable'
|
8
|
+
require 'empireavenue/error/not_found'
|
9
|
+
require 'empireavenue/error/service_unavailable'
|
10
|
+
#require 'empireavenue/error/too_many_requests'
|
11
|
+
#require 'empireavenue/error/unauthorized'
|
12
|
+
#require 'empireavenue/error/unprocessable_entity'
|
13
|
+
|
14
|
+
module EmpireAvenue
|
15
|
+
module Response
|
16
|
+
class RaiseError < Faraday::Response::Middleware
|
17
|
+
|
18
|
+
def on_complete(env)
|
19
|
+
status_code = env[:status].to_i
|
20
|
+
error_class = @klass.errors[status_code]
|
21
|
+
raise error_class.from_response(env) if error_class
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(app, klass)
|
25
|
+
@klass = klass
|
26
|
+
super(app)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module EmpireAvenue
|
2
|
+
class Version
|
3
|
+
MAJOR = 0 unless defined? Twitter::Version::MAJOR
|
4
|
+
MINOR = 0 unless defined? Twitter::Version::MINOR
|
5
|
+
PATCH = 1 unless defined? Twitter::Version::PATCH
|
6
|
+
PRE = nil unless defined? Twitter::Version::PRE
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
# @return [String]
|
11
|
+
def to_s
|
12
|
+
[MAJOR, MINOR, PATCH, PRE].compact.join('.')
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/empireavenue.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'empireavenue/default'
|
2
|
+
require 'empireavenue/client'
|
3
|
+
require 'empireavenue/configurable'
|
4
|
+
require 'empireavenue/entity'
|
5
|
+
require 'empireavenue/error'
|
6
|
+
require 'empireavenue/user'
|
7
|
+
|
8
|
+
module EmpireAvenue
|
9
|
+
class << self
|
10
|
+
include EmpireAvenue::Configurable
|
11
|
+
|
12
|
+
# Delegate to a EmpireAvenue::Client
|
13
|
+
#
|
14
|
+
# @return [EmpireAvenue::Client]
|
15
|
+
def client
|
16
|
+
@client = EmpireAvenue::Client.new(options) unless defined?(@client) && @client.hash == options.hash
|
17
|
+
end
|
18
|
+
|
19
|
+
def respond_to_missing?(method_name, include_private=false); client.respond_to?(method_name, include_private); end if RUBY_VERSION >= "1.9"
|
20
|
+
def respond_to?(method_name, include_private=false); client.respond_to?(method_name, include_private) || super; end if RUBY_VERSION < "1.9"
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def method_missing(method_name, *args, &block)
|
25
|
+
return super unless client.respond_to?(method_name)
|
26
|
+
client.send(method_name, *args, &block)
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
EmpireAvenue.setup
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::API::Portfolio do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
EmpireAvenue::Client.new(:client_id => "CK", :client_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@txwikinger_info = FactoryGirl.build(:portfolio_base_data, ticker: "TXWIKINGER")
|
11
|
+
@avidbeaver_info = FactoryGirl.build(:portfolio_base_data, ticker: "AVIDBEAVER")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "gets portfolio base info without ticker" do
|
15
|
+
stub_get("/portfolio/base").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
16
|
+
info = subject.portfolio_base
|
17
|
+
expect(a_get("/portfolio/base").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
18
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
19
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "gets portfolio base info with ticker" do
|
23
|
+
stub_get("/portfolio/base").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token, :ticker => "AVIDBEAVER"}).to_return(:body => FactoryGirl.build(:response, data: [@avidbeaver_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
24
|
+
info = subject.portfolio_base("AVIDBEAVER")
|
25
|
+
expect(a_get("/portfolio/base").with(:query => {:ticker => "AVIDBEAVER", :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
26
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
27
|
+
expect(info[:body][:data][0][:ticker]).to eq "AVIDBEAVER"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "gets page 2 of the portfolio base info" do
|
31
|
+
stub_get("/portfolio/base").with(:query => {:page => 2, :client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, requested_user: "AVIDBEAVER", requested_page: 2, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
32
|
+
info = subject.portfolio_base(nil, 2)
|
33
|
+
expect(a_get("/portfolio/base").with(:query => {:page => 2, :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
34
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
35
|
+
expect(info[:body][:meta][:requested_user]).to eq "AVIDBEAVER"
|
36
|
+
expect(info[:body][:meta][:requested_page]).to eq 2
|
37
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "gets portfolio base info with limit of 1 profile" do
|
41
|
+
stub_get("/portfolio/base").with(:query => {:maxresults => 1, :client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, requested_user: "AVIDBEAVER", requested_page: 1, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
42
|
+
info = subject.portfolio_base(nil, nil, 1)
|
43
|
+
expect(a_get("/portfolio/base").with(:query => {:maxresults => 1, :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
44
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
45
|
+
expect(info[:body][:meta][:requested_user]).to eq "AVIDBEAVER"
|
46
|
+
expect(info[:body][:meta][:requested_page]).to eq 1
|
47
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::API::Portfolio do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
EmpireAvenue::Client.new(:client_id => "CK", :client_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@txwikinger_info = FactoryGirl.build(:portfolio_get_data, ticker: "TXWIKINGER")
|
11
|
+
@avidbeaver_info = FactoryGirl.build(:portfolio_get_data, ticker: "AVIDBEAVER")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "gets portfolio info without ticker" do
|
15
|
+
stub_get("/portfolio/get").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
16
|
+
info = subject.portfolio_get
|
17
|
+
expect(a_get("/portfolio/get").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
18
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
19
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "gets portfolio info with ticker" do
|
23
|
+
stub_get("/portfolio/get").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token, :ticker => "AVIDBEAVER"}).to_return(:body => FactoryGirl.build(:response, data: [@avidbeaver_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
24
|
+
info = subject.portfolio_get("AVIDBEAVER")
|
25
|
+
expect(a_get("/portfolio/get").with(:query => {:ticker => "AVIDBEAVER", :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
26
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
27
|
+
expect(info[:body][:data][0][:ticker]).to eq "AVIDBEAVER"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "gets page 2 of the portfolio" do
|
31
|
+
stub_get("/portfolio/get").with(:query => {:page => 2, :client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, requested_user: "AVIDBEAVER", requested_page: 2, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
32
|
+
info = subject.portfolio_get(nil, 2)
|
33
|
+
expect(a_get("/portfolio/get").with(:query => {:page => 2, :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
34
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
35
|
+
expect(info[:body][:meta][:requested_user]).to eq "AVIDBEAVER"
|
36
|
+
expect(info[:body][:meta][:requested_page]).to eq 2
|
37
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "gets portfolio with limit of 1 profile" do
|
41
|
+
stub_get("/portfolio/get").with(:query => {:maxresults => 1, :client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, requested_user: "AVIDBEAVER", requested_page: 1, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
42
|
+
info = subject.portfolio_get(nil, nil, 1)
|
43
|
+
expect(a_get("/portfolio/get").with(:query => {:maxresults => 1, :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
44
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
45
|
+
expect(info[:body][:meta][:requested_user]).to eq "AVIDBEAVER"
|
46
|
+
expect(info[:body][:meta][:requested_page]).to eq 1
|
47
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::API::Portfolio do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
EmpireAvenue::Client.new(:client_id => "CK", :client_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@txwikinger_info = FactoryGirl.build(:portfolio_get_data, ticker: "TXWIKINGER")
|
11
|
+
@avidbeaver_info = FactoryGirl.build(:portfolio_get_data, ticker: "AVIDBEAVER")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "gets portfolio info without ticker" do
|
15
|
+
stub_get("/portfolio/get").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
16
|
+
info = subject.portfolio_get
|
17
|
+
expect(a_get("/portfolio/get").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
18
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
19
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "gets portfolio info with ticker" do
|
23
|
+
stub_get("/portfolio/get").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token, :ticker => "AVIDBEAVER"}).to_return(:body => FactoryGirl.build(:response, data: [@avidbeaver_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
24
|
+
info = subject.portfolio_get("AVIDBEAVER")
|
25
|
+
expect(a_get("/portfolio/get").with(:query => {:ticker => "AVIDBEAVER", :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
26
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
27
|
+
expect(info[:body][:data][0][:ticker]).to eq "AVIDBEAVER"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "gets page 2 of the portfolio" do
|
31
|
+
stub_get("/portfolio/get").with(:query => {:page => 2, :client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, requested_user: "AVIDBEAVER", requested_page: 2, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
32
|
+
info = subject.portfolio_get(nil, 2)
|
33
|
+
expect(a_get("/portfolio/get").with(:query => {:page => 2, :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
34
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
35
|
+
expect(info[:body][:meta][:requested_user]).to eq "AVIDBEAVER"
|
36
|
+
expect(info[:body][:meta][:requested_page]).to eq 2
|
37
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
38
|
+
end
|
39
|
+
|
40
|
+
it "gets portfolio with limit of 1 profile" do
|
41
|
+
stub_get("/portfolio/get").with(:query => {:maxresults => 1, :client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, requested_user: "AVIDBEAVER", requested_page: 1, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
42
|
+
info = subject.portfolio_get(nil, nil, 1)
|
43
|
+
expect(a_get("/portfolio/get").with(:query => {:maxresults => 1, :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
44
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
45
|
+
expect(info[:body][:meta][:requested_user]).to eq "AVIDBEAVER"
|
46
|
+
expect(info[:body][:meta][:requested_page]).to eq 1
|
47
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::API::Portfolio do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
EmpireAvenue::Client.new(:client_id => "CK", :client_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@txwikinger_info = FactoryGirl.build(:portfolio_get_data, ticker: "TXWIKINGER")
|
11
|
+
@avidbeaver_info = FactoryGirl.build(:portfolio_get_data, ticker: "AVIDBEAVER")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "gets portfolio info without ticker" do
|
15
|
+
stub_get("/portfolio/get").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
16
|
+
info = subject.portfolio_get
|
17
|
+
expect(a_get("/portfolio/get").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
18
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
19
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "gets portfolio info with ticker" do
|
23
|
+
stub_get("/portfolio/get").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token, :ticker => "AVIDBEAVER"}).to_return(:body => FactoryGirl.build(:response, data: [@avidbeaver_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
24
|
+
info = subject.portfolio_get("AVIDBEAVER")
|
25
|
+
expect(a_get("/portfolio/get").with(:query => {:ticker => "AVIDBEAVER", :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
26
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
27
|
+
expect(info[:body][:data][0][:ticker]).to eq "AVIDBEAVER"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "gets page 2 of the portfolio" do
|
31
|
+
stub_get("/portfolio/get").with(:query => {:page => 2, :client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, requested_user: "AVIDBEAVER", requested_page: 2, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
32
|
+
info = subject.portfolio_get(nil, 2)
|
33
|
+
expect(a_get("/portfolio/get").with(:query => {:page => 2, :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
34
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
35
|
+
expect(info[:body][:meta][:requested_user]).to eq "AVIDBEAVER"
|
36
|
+
expect(info[:body][:meta][:requested_page]).to eq 2
|
37
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::API::Profile do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
EmpireAvenue::Client.new(:client_id => "CK", :client_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "gets profile info without ticker" do
|
10
|
+
bank_balance_info = FactoryGirl.build(:profile_bank_balance_data)
|
11
|
+
stub_get("/profile/bank/balance").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, requested_user: "AVIDBEAVER", data: [bank_balance_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
12
|
+
info = subject.profile_bank_balance
|
13
|
+
expect(a_get("/profile/bank/balance").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
14
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
15
|
+
expect(info[:body][:meta][:requested_user]).to eq "AVIDBEAVER"
|
16
|
+
expect(info[:body][:data][0][:ticker]).to be_nil
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::API::Profile do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
EmpireAvenue::Client.new(:client_id => "CK", :client_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "gets profile info without ticker" do
|
10
|
+
bank_balance_info = FactoryGirl.build(:profile_bank_balance_data)
|
11
|
+
stub_get("/profile/bank/balance").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, requested_user: "AVIDBEAVER", data: [bank_balance_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
12
|
+
info = subject.profile_bank_balance
|
13
|
+
expect(a_get("/profile/bank/balance").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
14
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
15
|
+
expect(info[:body][:meta][:requested_user]).to eq "AVIDBEAVER"
|
16
|
+
expect(info[:body][:data][0][:ticker]).to eq "AVIDBEAVER"
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::API::Profile do
|
4
|
+
|
5
|
+
subject do
|
6
|
+
EmpireAvenue::Client.new(:client_id => "CK", :client_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@txwikinger_info = FactoryGirl.build(:profile_info_data, ticker: "TXWIKINGER")
|
11
|
+
@avidbeaver_info = FactoryGirl.build(:profile_info_data, ticker: "AVIDBEAVER")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "gets profile info without ticker" do
|
15
|
+
stub_get("/profile/info").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, data: [@txwikinger_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
16
|
+
info = subject.profile_info
|
17
|
+
expect(a_get("/profile/info").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
18
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
19
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "gets profile info with ticker" do
|
23
|
+
stub_get("/profile/info").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token, :ticker => "AVIDBEAVER"}).to_return(:body => FactoryGirl.build(:response, data: [@avidbeaver_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
24
|
+
info = subject.profile_info("AVIDBEAVER")
|
25
|
+
expect(a_get("/profile/info").with(:query => {:ticker => "AVIDBEAVER", :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
26
|
+
expect(info[:body][:meta][:total_rows]).to eq 1
|
27
|
+
expect(info[:body][:data][0][:ticker]).to eq "AVIDBEAVER"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "gets profile info with multiple tickers" do
|
31
|
+
stub_get("/profile/info").with(:query => {:ticker => "TXWIKINGER,AVIDBEAVER", :client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, data: [@txwikinger_info, @avidbeaver_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
32
|
+
info = subject.profile_info(["TXWIKINGER", "AVIDBEAVER"])
|
33
|
+
expect(a_get("/profile/info").with(:query => {:ticker => "TXWIKINGER,AVIDBEAVER", :client_id => subject.client_id, :access_token => subject.oauth_token})).to have_been_made
|
34
|
+
expect(info[:body][:meta][:total_rows]).to eq 2
|
35
|
+
expect(info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
36
|
+
expect(info[:body][:data][1][:ticker]).to eq "AVIDBEAVER"
|
37
|
+
end
|
38
|
+
end
|