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,149 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::Client 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
|
+
context "with module configuration" do
|
10
|
+
|
11
|
+
before do
|
12
|
+
EmpireAvenue.configure do |config|
|
13
|
+
EmpireAvenue::Configurable.keys.each do |key|
|
14
|
+
config.send("#{key}=", key)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
after do
|
20
|
+
EmpireAvenue.reset!
|
21
|
+
end
|
22
|
+
|
23
|
+
it "inherits the module configuration" do
|
24
|
+
client = EmpireAvenue::Client.new
|
25
|
+
EmpireAvenue::Configurable.keys.each do |key|
|
26
|
+
expect(client.instance_variable_get(:"@#{key}")).to eq key
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with class configuration" do
|
31
|
+
|
32
|
+
before do
|
33
|
+
@configuration = {
|
34
|
+
:connection_options => {:timeout => 10},
|
35
|
+
:client_id => 'CK',
|
36
|
+
:client_secret => 'CS',
|
37
|
+
:endpoint => 'http://tumblr.com/',
|
38
|
+
:middleware => Proc.new{},
|
39
|
+
:oauth_token => 'OT',
|
40
|
+
:oauth_token_secret => 'OS',
|
41
|
+
:identity_map => ::Hash
|
42
|
+
}
|
43
|
+
end
|
44
|
+
|
45
|
+
context "during initialization" do
|
46
|
+
it "overrides the module configuration" do
|
47
|
+
client = EmpireAvenue::Client.new(@configuration)
|
48
|
+
EmpireAvenue::Configurable.keys.each do |key|
|
49
|
+
expect(client.instance_variable_get(:"@#{key}")).to eq @configuration[key]
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "after initialization" do
|
55
|
+
it "overrides the module configuration after initialization" do
|
56
|
+
client = EmpireAvenue::Client.new
|
57
|
+
client.configure do |config|
|
58
|
+
@configuration.each do |key, value|
|
59
|
+
config.send("#{key}=", value)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
EmpireAvenue::Configurable.keys.each do |key|
|
63
|
+
expect(client.instance_variable_get(:"@#{key}")).to eq @configuration[key]
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
it "does not cache the ticker across clients" do
|
72
|
+
txwikinger_info = FactoryGirl.build(:profile_info_data, ticker: "TXWIKINGER")
|
73
|
+
avidbeaver_info = FactoryGirl.build(:profile_info_data, ticker: "AVIDBEAVER")
|
74
|
+
|
75
|
+
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"})
|
76
|
+
client1 = EmpireAvenue::Client.new(:client_id => "CK", :client_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
|
77
|
+
expect(client1.profile_info[:body][:data][0][:ticker]).to eq "TXWIKINGER"
|
78
|
+
stub_get("/profile/info").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}).to_return(:body => FactoryGirl.build(:response, data: [avidbeaver_info]).to_json, :headers => {:content_type => "application/json; charset=utf-8"})
|
79
|
+
client2 = EmpireAvenue::Client.new(:client_id => "CK", :client_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
|
80
|
+
expect(client2.profile_info[:body][:data][0][:ticker]).to eq "AVIDBEAVER"
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#post" do
|
84
|
+
before do
|
85
|
+
#@client = EmpireAvenue::Client.new
|
86
|
+
stub_post("/shares/buy").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}, :body => {"shares" => "1", "ticker" => "AVIDBEAVER", "last_trade" => "150.445"})
|
87
|
+
end
|
88
|
+
it "allows custom post requests" do
|
89
|
+
subject.post("/shares/buy", {:shares => 1, :ticker => "AVIDBEAVER", :last_trade => 150.445})
|
90
|
+
expect(a_post("/shares/buy").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}, :body => 'shares=1&ticker=AVIDBEAVER&last_trade=150.445')).to have_been_made
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe "#delete" do
|
95
|
+
before do
|
96
|
+
#@client = EmpireAvenue::Client.new
|
97
|
+
stub_delete("/custom/delete").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}.merge({:deleted => "object"}))
|
98
|
+
end
|
99
|
+
it "allows custom delete requests" do
|
100
|
+
subject.delete("/custom/delete", {:deleted => "object"})
|
101
|
+
expect(a_delete("/custom/delete").with(:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}.merge({:deleted => "object"}))).to have_been_made
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#put" do
|
106
|
+
before do
|
107
|
+
stub_put("/custom/put").with({:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}, :body => {:updated => "object"}})
|
108
|
+
end
|
109
|
+
it "allows custom put requests" do
|
110
|
+
pending "odd split method not found error"
|
111
|
+
subject.put("/custom/put", {:updated => "object"})
|
112
|
+
expect(a_put("/custom/put").with({:query => {:client_id => subject.client_id, :access_token => subject.oauth_token}, :body => {:updated => "object"}})).to have_been_made
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#credentials?" do
|
117
|
+
it "returns true if all credentials are present" do
|
118
|
+
client = EmpireAvenue::Client.new(:client_id => 'CK', :client_secret => 'CS', :oauth_token => 'OT', :oauth_token_secret => 'OS')
|
119
|
+
expect(client.credentials?).to be_true
|
120
|
+
end
|
121
|
+
it "returns false if any credentials are missing" do
|
122
|
+
client = EmpireAvenue::Client.new(:client_id => 'CK', :client_secret => 'CS', :oauth_token => 'OT')
|
123
|
+
expect(client.credentials?).to be_false
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
describe "#connection" do
|
128
|
+
it "looks like Faraday connection" do
|
129
|
+
expect(subject.send(:connection)).to respond_to(:run_request)
|
130
|
+
end
|
131
|
+
it "memoizes the connection" do
|
132
|
+
c1, c2 = subject.send(:connection), subject.send(:connection)
|
133
|
+
expect(c1.object_id).to eq c2.object_id
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "#request" do
|
138
|
+
it "catches Faraday errors" do
|
139
|
+
subject.stub!(:connection).and_raise(Faraday::Error::ClientError.new("Oops"))
|
140
|
+
expect{subject.send(:request, :get, "/path")}.to raise_error EmpireAvenue::Error::ClientError
|
141
|
+
end
|
142
|
+
it "catches MultiJson::DecodeError errors" do
|
143
|
+
subject.stub!(:connection).and_raise(MultiJson::DecodeError.new("unexpected token", [], "<!DOCTYPE html>"))
|
144
|
+
expect{subject.send(:request, :get, "/path")}.to raise_error EmpireAvenue::Error::DecodeError
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
|
149
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::Error::ClientError do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = EmpireAvenue::Client.new({:client_id => "id", :oauth_token => "ot"})
|
7
|
+
end
|
8
|
+
|
9
|
+
it "has correct faraday environment built" do
|
10
|
+
@client.middleware.handlers.should include(EmpireAvenue::Response::RaiseError, Faraday::Adapter::NetHttp)
|
11
|
+
end
|
12
|
+
|
13
|
+
EmpireAvenue::Error::ClientError.errors.each do |status, exception|
|
14
|
+
[nil, "error", "errors"].each do |body|
|
15
|
+
context "when HTTP status is #{status} and body is #{body.inspect}" do
|
16
|
+
before do
|
17
|
+
body_message = '{"' + body + '":"Client Error"}' unless body.nil?
|
18
|
+
stub_get("/profile/info").with(:query => {:client_id => @client.client_id, :access_token => @client.oauth_token}.merge({ :ticker => 'avidbeaver'})).to_return(:status => status, :body => body_message)
|
19
|
+
end
|
20
|
+
it "raises #{exception.name}" do
|
21
|
+
expect{@client.profile_info('avidbeaver')}.to raise_error exception
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::Error::ClientError do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = EmpireAvenue::Client.new({:client_id => "id", :oauth_token => "ot"})
|
7
|
+
end
|
8
|
+
|
9
|
+
it "has correct faraday environment built" do
|
10
|
+
@client.middleware.handlers.should include(EmpireAvenue::Response::RaiseError, Faraday::Adapter::NetHttp)
|
11
|
+
end
|
12
|
+
|
13
|
+
EmpireAvenue::Error::ClientError.errors.each do |status, exception|
|
14
|
+
[nil, "error", "errors"].each do |body|
|
15
|
+
context "when HTTP status is #{status} and body is #{body.inspect}" do
|
16
|
+
before do
|
17
|
+
body_message = '{"' + body + '":"Client Error"}' unless body.nil?
|
18
|
+
stub_get("/profile/info").with(:query => {:client_id => @client.client_id, :access_token => @client.oauth_token}.merge({ :ticker => 'txwikinger'})).to_return(:status => status, :body => body_message)
|
19
|
+
end
|
20
|
+
it "raises #{exception.name}" do
|
21
|
+
expect{@client.profile_info('txwikinger')}.to raise_error exception
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::Error::ServerError do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = EmpireAvenue::Client.new(:client_id => "CK", :client_secret => "CS", :oauth_token => "OT", :oauth_token_secret => "OS")
|
7
|
+
end
|
8
|
+
|
9
|
+
EmpireAvenue::Error::ServerError.errors.each do |status, exception|
|
10
|
+
context "when HTTP status is #{status}" do
|
11
|
+
before do
|
12
|
+
stub_get("/profile/info").with(:query => {:client_id => @client.client_id, :access_token => @client.oauth_token}.merge({:ticker => 'txwikinger'})).to_return(:status => status)
|
13
|
+
end
|
14
|
+
it "raises #{exception.name}" do
|
15
|
+
expect{@client.profile_info('txwikinger')}.to raise_error exception
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::Error::ServerError do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@client = EmpireAvenue::Client.new
|
7
|
+
end
|
8
|
+
|
9
|
+
EmpireAvenue::Error::ServerError.errors.each do |status, exception|
|
10
|
+
context "when HTTP status is #{status}" do
|
11
|
+
before do
|
12
|
+
stub_get("/profile/info").with(:query => {:client_id => @client.client_id, :access_token => @client.oauth_token}.merge({:ticker => 'txwikinger'})).to_return(:status => status)
|
13
|
+
end
|
14
|
+
it "raises #{exception.name}" do
|
15
|
+
expect{@client.profile_info('txwikinger')}.to raise_error exception
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::Error do
|
4
|
+
|
5
|
+
describe "#initialize" do
|
6
|
+
it "wraps another error class" do
|
7
|
+
begin
|
8
|
+
raise Faraday::Error::ClientError.new("Oops")
|
9
|
+
rescue Faraday::Error::ClientError
|
10
|
+
begin
|
11
|
+
raise EmpireAvenue::Error
|
12
|
+
rescue EmpireAvenue::Error => error
|
13
|
+
expect(error.message).to eq "Oops"
|
14
|
+
expect(error.wrapped_exception.class).to eq Faraday::Error::ClientError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::Error do
|
4
|
+
|
5
|
+
describe "#initialize" do
|
6
|
+
it "wraps another error class" do
|
7
|
+
begin
|
8
|
+
raise Faraday::Error::ClientError.new("Oops")
|
9
|
+
rescue Faraday::Error::ClientError
|
10
|
+
begin
|
11
|
+
raise Twitter::Error
|
12
|
+
rescue Twitter::Error => error
|
13
|
+
expect(error.message).to eq "Oops"
|
14
|
+
expect(error.wrapped_exception.class).to eq Faraday::Error::ClientError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::Identity do
|
4
|
+
|
5
|
+
describe "#initialize" do
|
6
|
+
it "raises an ArgumentError when type is not specified" do
|
7
|
+
expect{EmpireAvenue::Identity.new}.to raise_error ArgumentError
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context "identity map enabled" do
|
12
|
+
before do
|
13
|
+
EmpireAvenue.identity_map = EmpireAvenue::IdentityMap
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
EmpireAvenue.identity_map = false
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".fetch" do
|
21
|
+
it "returns existing objects" do
|
22
|
+
EmpireAvenue::Identity.store(EmpireAvenue::Identity.new(:id => 1))
|
23
|
+
expect(EmpireAvenue::Identity.fetch(:id => 1)).to be
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises an error on objects that don't exist" do
|
27
|
+
expect{EmpireAvenue::Identity.fetch(:id => 6)}.to raise_error EmpireAvenue::Error::IdentityMapKeyError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#==" do
|
33
|
+
it "returns true when objects IDs are the same" do
|
34
|
+
one = EmpireAvenue::Identity.new(:id => 1, :screen_name => "avidbeaver")
|
35
|
+
two = EmpireAvenue::Identity.new(:id => 1, :screen_name => "txwikinger")
|
36
|
+
expect(one == two).to be_true
|
37
|
+
end
|
38
|
+
it "returns false when objects IDs are different" do
|
39
|
+
one = EmpireAvenue::Identity.new(:id => 1)
|
40
|
+
two = EmpireAvenue::Identity.new(:id => 2)
|
41
|
+
expect(one == two).to be_false
|
42
|
+
end
|
43
|
+
it "returns false when classes are different" do
|
44
|
+
one = EmpireAvenue::Identity.new(:id => 1)
|
45
|
+
two = EmpireAvenue::Base.new(:id => 1)
|
46
|
+
expect(one == two).to be_false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
describe EmpireAvenue::Identity do
|
4
|
+
|
5
|
+
describe "#initialize" do
|
6
|
+
it "raises an ArgumentError when type is not specified" do
|
7
|
+
expect{EmpireAvenue::Identity.new}.to raise_error ArgumentError
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
context "identity map enabled" do
|
12
|
+
before do
|
13
|
+
EmpireAvenue.identity_map = EmpireAvenue::IdentityMap
|
14
|
+
end
|
15
|
+
|
16
|
+
after do
|
17
|
+
EmpireAvenue.identity_map = false
|
18
|
+
end
|
19
|
+
|
20
|
+
describe ".fetch" do
|
21
|
+
it "returns existing objects" do
|
22
|
+
EmpireAvenue::Identity.store(EmpireAvenue::Identity.new(:id => 1))
|
23
|
+
expect(EmpireAvenue::Identity.fetch(:id => 1)).to be
|
24
|
+
end
|
25
|
+
|
26
|
+
it "raises an error on objects that don't exist" do
|
27
|
+
expect{EmpireAvenue::Identity.fetch(:id => 6)}.to raise_error EmpireAvenue::Error::IdentityMapKeyError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#==" do
|
33
|
+
it "returns true when objects IDs are the same" do
|
34
|
+
one = EmpireAvenue::Identity.new(:id => 1, :screen_name => "sferik")
|
35
|
+
two = EmpireAvenue::Identity.new(:id => 1, :screen_name => "garybernhardt")
|
36
|
+
expect(one == two).to be_true
|
37
|
+
end
|
38
|
+
it "returns false when objects IDs are different" do
|
39
|
+
one = EmpireAvenue::Identity.new(:id => 1)
|
40
|
+
two = EmpireAvenue::Identity.new(:id => 2)
|
41
|
+
expect(one == two).to be_false
|
42
|
+
end
|
43
|
+
it "returns false when classes are different" do
|
44
|
+
one = EmpireAvenue::Identity.new(:id => 1)
|
45
|
+
two = EmpireAvenue::Base.new(:id => 1)
|
46
|
+
expect(one == two).to be_false
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module EmpireAvenue
|
4
|
+
module Rspec
|
5
|
+
module API
|
6
|
+
class Response
|
7
|
+
|
8
|
+
@meta_vars = [:requested_user, :total_rows, :requested_page, :next_page, :prev_page, :total_pages, :uri, :limit, :limit_type, :requests, :reset, :recorded]
|
9
|
+
|
10
|
+
@meta_vars.each {|attr| attr_accessor attr}
|
11
|
+
|
12
|
+
attr_accessor :data
|
13
|
+
|
14
|
+
def self.meta_vars
|
15
|
+
@meta_vars
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@data = []
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_json
|
23
|
+
hash.to_json
|
24
|
+
end
|
25
|
+
|
26
|
+
def meta_hash
|
27
|
+
hashify(self, self.class.meta_vars)
|
28
|
+
end
|
29
|
+
|
30
|
+
def data_hash
|
31
|
+
@data.collect { |obj| hashify(obj, obj.class.data_vars) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def hash
|
35
|
+
hash = {}
|
36
|
+
hash[:meta] = meta_hash unless meta_hash.empty?
|
37
|
+
hash[:data] = data_hash unless data_hash.empty?
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
include
|
41
|
+
protected
|
42
|
+
|
43
|
+
def hashify (obj, set)
|
44
|
+
Hash[set.map do |name|
|
45
|
+
value = obj.instance_variable_get("@#{name}")
|
46
|
+
[name, value] if value
|
47
|
+
end]
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
module Data
|
54
|
+
|
55
|
+
|
56
|
+
def data_vars
|
57
|
+
@data_vars
|
58
|
+
end
|
59
|
+
|
60
|
+
def meta_vars
|
61
|
+
@meta_vars
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
class ProfileInfoData
|
67
|
+
extend Data
|
68
|
+
|
69
|
+
@data_vars = [:ticker, :first_name, :last_name, :full_name, :site_name, :site_url, :country, :location, :joined, :type, :max_shares, :commission, :last_trade, :outstanding_shares, :total_shares, :close, :close_money, :open, :yesterday_lowest, :yesterday_change, :yesterday_highest, :volume, :market_last_close, :market_last_open, :current_status, :current_status_set, :trading_status, :sm_portrait, :lg_portrait, :investments_count, :shareholders_count, :thumbs_up_count, :thumbs_down_count, :shares_owned_count, :listed_count, :recommended_count, :held_shares, :avg_div_per_share, :eav_score, :facebook_score, :flickr_score, :foursquare_score, :gplus_score, :instagram_score, :linkedin_score, :twitter_score, :youtube_score]
|
70
|
+
|
71
|
+
@data_vars.each {|attr| attr_accessor attr}
|
72
|
+
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
class ProfileBankBalanceData
|
77
|
+
extend Data
|
78
|
+
|
79
|
+
@data_vars = [:balance]
|
80
|
+
|
81
|
+
@data_vars.each {|attr| attr_accessor attr}
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
class ProfileShareholdersData
|
86
|
+
extend Data
|
87
|
+
|
88
|
+
@data_vars = [:ticker, :full_name, :last_trade, :close, :yesterday_lowest, :yesterday_highest, :sm_portrait, :lg_portrait, :location, :outstanding_shares, :country, :portfolio_value, :yesterday_earnings, :eav_score, :facebook_score, :flickr_score, :foursquare_score, :gplus_score, :instagram_score, :linkedin_score, :twitter_score, :youtube_score, :shares, :last_buy_shares, :last_buy, :your_shares_held, :max_shares]
|
89
|
+
|
90
|
+
@data_vars.each {|attr| attr_accessor attr}
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
class PortfolioGetData
|
95
|
+
extend Data
|
96
|
+
|
97
|
+
@data_vars = [:ticker, :full_name, :last_trade, :close, :yesterday_lowest, :yesterday_highest, :sm_portrait, :lg_portrait, :location, :outstanding_shares, :country, :portfolio_value, :yesterday_earnings, :eav_score, :facebook_score, :flickr_score, :foursquare_score, :gplus_score, :instagram_score, :linkedin_score, :twitter_score, :youtube_score, :shares, :last_buy_shares, :last_buy, :your_shares_held, :max_shares]
|
98
|
+
|
99
|
+
@data_vars.each {|attr| attr_accessor attr}
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
class PortfolioBaseData
|
104
|
+
extend Data
|
105
|
+
|
106
|
+
@data_vars = [:full_name, :last_trade, :close, :ticker, :eav_score, :facebook_score, :flickr_score, :foursquare_score, :gplus_score, :instagram_score, :linkedin_score, :twitter_score, :youtube_score]
|
107
|
+
|
108
|
+
@data_vars.each {|attr| attr_accessor attr}
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
class SearchRecentData
|
113
|
+
extend Data
|
114
|
+
|
115
|
+
@data_vars = [:ticker, :full_name, :last_trade, :close, :sm_portrait, :lg_portrait, :location, :outstanding_shares, :country, :created, :max_shares, :eav_score, :facebook_score, :flickr_score, :foursquare_score, :gplus_score, :instagram_score, :linkedin_score, :twitter_score, :youtube_score]
|
116
|
+
@data_vars.each {|attr| attr_accessor attr}
|
117
|
+
end
|
118
|
+
|
119
|
+
class SharesBuyData
|
120
|
+
extend Data
|
121
|
+
|
122
|
+
@data_vars = [:success, :shares_owned, :commission, :total_charged, :bank_balance]
|
123
|
+
|
124
|
+
@data_vars.each {|attr| attr_accessor attr}
|
125
|
+
end
|
126
|
+
|
127
|
+
class SharesSellData
|
128
|
+
extend Data
|
129
|
+
|
130
|
+
@data_vars = [:success, :shares_owned, :commission, :bank_balance, :total_earned]
|
131
|
+
|
132
|
+
@data_vars.each {|attr| attr_accessor attr}
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module EmpireAvenue
|
4
|
+
module Rspec
|
5
|
+
module API
|
6
|
+
class Response
|
7
|
+
|
8
|
+
@meta_vars = [:requested_user, :total_rows, :requested_page, :next_page, :prev_page, :total_pages, :uri, :limit, :limit_type, :requests, :reset, :recorded]
|
9
|
+
|
10
|
+
@meta_vars.each {|attr| attr_accessor attr}
|
11
|
+
|
12
|
+
attr_accessor :data
|
13
|
+
|
14
|
+
def self.meta_vars
|
15
|
+
@meta_vars
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@data = []
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_json
|
23
|
+
hash.to_json
|
24
|
+
end
|
25
|
+
|
26
|
+
def meta_hash
|
27
|
+
hashify(self, self.class.meta_vars)
|
28
|
+
end
|
29
|
+
|
30
|
+
def data_hash
|
31
|
+
@data.collect { |obj| hashify(obj, obj.class.data_vars) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def hash
|
35
|
+
hash = {}
|
36
|
+
hash[:meta] = meta_hash unless meta_hash.empty?
|
37
|
+
hash[:data] = data_hash unless data_hash.empty?
|
38
|
+
hash
|
39
|
+
end
|
40
|
+
include
|
41
|
+
protected
|
42
|
+
|
43
|
+
def hashify (obj, set)
|
44
|
+
Hash[set.map do |name|
|
45
|
+
value = obj.instance_variable_get("@#{name}")
|
46
|
+
[name, value] if value
|
47
|
+
end]
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
module Data
|
54
|
+
|
55
|
+
|
56
|
+
def data_vars
|
57
|
+
@data_vars
|
58
|
+
end
|
59
|
+
|
60
|
+
def meta_vars
|
61
|
+
@meta_vars
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
class ProfileInfoData
|
67
|
+
extend Data
|
68
|
+
|
69
|
+
@data_vars = [:ticker, :first_name, :last_name, :full_name, :site_name, :site_url, :country, :location, :joined, :type, :max_shares, :commission, :last_trade, :outstanding_shares, :total_shares, :close, :close_money, :open, :yesterday_lowest, :yesterday_change, :yesterday_highest, :volume, :market_last_close, :market_last_open, :current_status, :current_status_set, :trading_status, :sm_portrait, :lg_portrait, :investments_count, :shareholders_count, :thumbs_up_count, :thumbs_down_count, :shares_owned_count, :listed_count, :recommended_count, :held_shares, :avg_div_per_share, :eav_score, :facebook_score, :flickr_score, :foursquare_score, :gplus_score, :instagram_score, :linkedin_score, :twitter_score, :youtube_score]
|
70
|
+
|
71
|
+
@data_vars.each {|attr| attr_accessor attr}
|
72
|
+
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
class ProfileBankBalanceData
|
77
|
+
extend Data
|
78
|
+
|
79
|
+
@data_vars = [:balance]
|
80
|
+
|
81
|
+
@data_vars.each {|attr| attr_accessor attr}
|
82
|
+
|
83
|
+
end
|
84
|
+
|
85
|
+
class ProfileShareholdersData
|
86
|
+
extend Data
|
87
|
+
|
88
|
+
@data_vars = [:ticker, :full_name, :last_trade, :close, :yesterday_lowest, :yesterday_highest, :sm_portrait, :lg_portrait, :location, :outstanding_shares, :country, :portfolio_value, :yesterday_earnings, :eav_score, :facebook_score, :flickr_score, :foursquare_score, :gplus_score, :instagram_score, :linkedin_score, :twitter_score, :youtube_score, :shares, :last_buy_shares, :last_buy, :your_shares_held, :max_shares]
|
89
|
+
|
90
|
+
@data_vars.each {|attr| attr_accessor attr}
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
class PortfolioGetData
|
95
|
+
extend Data
|
96
|
+
|
97
|
+
@data_vars = [:ticker, :full_name, :last_trade, :close, :yesterday_lowest, :yesterday_highest, :sm_portrait, :lg_portrait, :location, :outstanding_shares, :country, :portfolio_value, :yesterday_earnings, :eav_score, :facebook_score, :flickr_score, :foursquare_score, :gplus_score, :instagram_score, :linkedin_score, :twitter_score, :youtube_score, :shares, :last_buy_shares, :last_buy, :your_shares_held, :max_shares]
|
98
|
+
|
99
|
+
@data_vars.each {|attr| attr_accessor attr}
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
class PortfolioBaseData
|
104
|
+
extend Data
|
105
|
+
|
106
|
+
@data_vars = [:full_name, :last_trade, :close, :ticker, :eav_score, :facebook_score, :flickr_score, :foursquare_score, :gplus_score, :instagram_score, :linkedin_score, :twitter_score, :youtube_score]
|
107
|
+
|
108
|
+
@data_vars.each {|attr| attr_accessor attr}
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
class SearchRecentData
|
113
|
+
extend Data
|
114
|
+
|
115
|
+
@data_vars = [:ticker, :full_name, :last_trade, :close, :sm_portrait, :lg_portrait, :location, :outstanding_shares, :country, :created, :max_shares, :eav_score, :facebook_score, :flickr_score, :foursquare_score, :gplus_score, :instagram_score, :linkedin_score, :twitter_score, :youtube_score]
|
116
|
+
@data_vars.each {|attr| attr_accessor attr}
|
117
|
+
end
|
118
|
+
|
119
|
+
class SharesBuyData
|
120
|
+
extend Data
|
121
|
+
|
122
|
+
@data_vars = [:success, :shares_owned, :commission, :total_charged, :bank_balance]
|
123
|
+
|
124
|
+
@data_vars.each {|attr| attr_accessor attr}
|
125
|
+
end
|
126
|
+
|
127
|
+
class SharesSellData
|
128
|
+
extend Data
|
129
|
+
|
130
|
+
@data_vars = [:success, :shares_owned, :commission, :bank_balance, :total_earned]
|
131
|
+
|
132
|
+
@data_vars.each {|attr| attr_accessor attr}
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|