vestorly_api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe VestorlyApi::DefaultEndpoint do
4
+
5
+ subject { VestorlyApi::DefaultEndpoint }
6
+
7
+ describe 'default values for API' do
8
+ it 'gives the base url to Vestorly endpoint' do
9
+ subject.base_api_uri.should eq('https://vestorly-dev.herokuapp.com/')
10
+ end
11
+
12
+ it 'gives the base Vestory API endpoint' do
13
+ subject.default_api_endpoint.should eq('https://vestorly-dev.herokuapp.com/api/v1')
14
+ end
15
+
16
+ it 'gives the Vestorly API version' do
17
+ subject.api_version.should eq(1)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,92 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ describe VestorlyApi::Member do
5
+
6
+ def api_request_helper(requester, end_point, request_params)
7
+ requester.get(
8
+ end_point,
9
+ query: request_params
10
+ )
11
+ end
12
+
13
+ let(:username) { 'david@vestorly.com' }
14
+ let(:password) { '12desbrosses' }
15
+ let(:advisor_id) { 'rodas' }
16
+
17
+ let(:request_params) { {
18
+ username: username,
19
+ password: password
20
+ }}
21
+
22
+ let(:authentication_token) { "eyJwYXlsb2FkIjoiNTM0ZDllYmZiMDM0ZDUwMDAyMDAwNGZkIiwiY3JlYXRlZF9vbiI6MTQxMTA3OTcxMywic2lnbmF0dXJlIjoiWTdxTmpjemZkelZDV2t4bEt6djVwWlZzand1eGx0NE1DREYwODNjR2FpQT0ifQ" }
23
+
24
+ before do
25
+ VestorlyApi::SignIn.any_instance.stub(:sign_in).with(username, password).and_return { authentication_token }
26
+ VestorlyApi::SignIn.any_instance.stub(:authentication_token).and_return { authentication_token }
27
+ VestorlyApi::SignIn.any_instance.stub(:advisor_id).and_return { advisor_id }
28
+ @sign_in_api = VestorlyApi::SignIn.new(username, password)
29
+ end
30
+
31
+ describe 'default attributes' do
32
+
33
+ subject { described_class }
34
+
35
+ it 'should include httparty methods' do
36
+ subject.should include(HTTParty)
37
+ end
38
+
39
+ end
40
+
41
+ describe 'fetch members' do
42
+
43
+ describe 'with valid parameters' do
44
+
45
+ before do
46
+ VCR.insert_cassette 'fetch_members', :record => :new_episodes
47
+ end
48
+
49
+ after do
50
+ VCR.eject_cassette
51
+ end
52
+
53
+ it 'records the fixture' do
54
+ members_api = described_class.new(@sign_in_api)
55
+ members_api.fetch({ 'filter_by' => 'prospects' })
56
+ end
57
+
58
+ it 'fetch members' do
59
+ members_api = described_class.new(@sign_in_api)
60
+ fetched_members = members_api.fetch({ 'filter_by' => 'prospects' })
61
+ fetched_members.size.should eq(34)
62
+ end
63
+
64
+ it 'fetch members have requested fields' do
65
+ members_api = described_class.new(@sign_in_api)
66
+ fetched_members = members_api.fetch({ 'filter_by' => 'prospects' })
67
+ fetched_members[0]['_id'].should eq('53a4c1acfc4674b330000019')
68
+ end
69
+
70
+ end
71
+
72
+ describe 'with invalid token' do
73
+
74
+ let(:authentication_token) { "invalid" }
75
+
76
+ before do
77
+ VCR.insert_cassette 'invalid_fetch_members', :record => :new_episodes
78
+ end
79
+
80
+ after do
81
+ VCR.eject_cassette
82
+ end
83
+
84
+ it 'fetch raise exception' do
85
+ members_api = described_class.new(@sign_in_api)
86
+ expect { members_api.fetch }.to raise_error( VestorlyApi::Exceptions::Error )
87
+ end
88
+ end
89
+
90
+ end
91
+
92
+ end
@@ -0,0 +1,108 @@
1
+ require 'spec_helper'
2
+
3
+ describe VestorlyApi::SignIn do
4
+
5
+ def api_request_helper(requester, request_params)
6
+ requester.post(
7
+ requester.sign_in_api_endpoint,
8
+ query: request_params
9
+ )
10
+ end
11
+
12
+ describe 'default attributes' do
13
+
14
+ subject { described_class }
15
+
16
+ it 'should include httparty methods' do
17
+ subject.should include(HTTParty)
18
+ end
19
+
20
+ it 'should have the base url set to the VestorlyApi API endpoint' do
21
+ subject.sign_in_api_endpoint.should eq('https://vestorly-dev.herokuapp.com/api/v1/session_management/sign_in?version=1')
22
+ end
23
+ end
24
+
25
+ describe 'sign_in api' do
26
+ describe "POST sign_in" do
27
+
28
+ describe "with valid authentication" do
29
+
30
+ let(:username) { 'david@vestorly.com' }
31
+ let(:password) { '12desbrosses' }
32
+
33
+ let(:request_params) { {
34
+ username: username,
35
+ password: password
36
+ }}
37
+
38
+ subject { described_class }
39
+
40
+ before do
41
+ VCR.insert_cassette 'sign_in', :record => :new_episodes
42
+ end
43
+
44
+ after do
45
+ VCR.eject_cassette
46
+ end
47
+
48
+ it 'records the fixture' do
49
+ api_request_helper(subject, request_params)
50
+ end
51
+
52
+ it 'makes sign_in request to api returns authentication token' do
53
+ sign_in_api = described_class.new(username, password)
54
+ sign_in_api.sign_in.should eq("eyJwYXlsb2FkIjoiNTM0ZDllYmZiMDM0ZDUwMDAyMDAwNGZkIiwiY3JlYXRlZF9vbiI6MTQxMTA4Mzg0Niwic2lnbmF0dXJlIjoiVUZtcmU5REZUb0V1KzNBY2dTajdGRTJlZVJ2REl0S0Nmbm1Mbzh5cWpIVT0ifQ")
55
+ end
56
+
57
+ it 'assigns api response for further use' do
58
+ sign_in_api = described_class.new(username, password)
59
+ sign_in_api.sign_in
60
+ sign_in_api.instance_variable_get('@sign_in_response').should_not be_nil
61
+ end
62
+
63
+ it 'gives authentication token after sign_in' do
64
+ sign_in_api = described_class.new(username, password)
65
+ sign_in_api.sign_in
66
+ sign_in_api.authentication_token.should eq("eyJwYXlsb2FkIjoiNTM0ZDllYmZiMDM0ZDUwMDAyMDAwNGZkIiwiY3JlYXRlZF9vbiI6MTQxMTA4Mzg0Niwic2lnbmF0dXJlIjoiVUZtcmU5REZUb0V1KzNBY2dTajdGRTJlZVJ2REl0S0Nmbm1Mbzh5cWpIVT0ifQ")
67
+ end
68
+
69
+ it 'gives the advisor id' do
70
+ sign_in_api = described_class.new(username, password)
71
+ sign_in_api.sign_in
72
+ sign_in_api.advisor_id.should eq("rodas")
73
+ end
74
+ end
75
+
76
+ describe "with invalid authentication" do
77
+ let(:username) { 'invalid@example.com' }
78
+ let(:password) { 'nonexistingdude' }
79
+
80
+ let(:request_params) { {
81
+ username: username,
82
+ password: password
83
+ }}
84
+
85
+ subject { described_class }
86
+
87
+ before do
88
+ VCR.insert_cassette 'invalid_sign_in', :record => :new_episodes
89
+ end
90
+
91
+ after do
92
+ VCR.eject_cassette
93
+ end
94
+
95
+ it 'records the fixture' do
96
+ api_request_helper(subject, request_params)
97
+ end
98
+
99
+ it 'raise unauthorized sign_in error' do
100
+ sign_in_api = described_class.new(username, password)
101
+ expect { sign_in_api.sign_in }.to raise_error( VestorlyApi::Exceptions::Error )
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe VestorlyApi::SignOut do
4
+ def api_request_helper(requester, request_params)
5
+ requester.post(
6
+ requester.sign_out_api_endpoint,
7
+ query: request_params
8
+ )
9
+ end
10
+
11
+ describe 'default attributes' do
12
+
13
+ subject { described_class }
14
+
15
+ it 'should include httparty methods' do
16
+ subject.should include(HTTParty)
17
+ end
18
+
19
+ it 'should have the base url set to the VestorlyApi API endpoint' do
20
+ subject.sign_out_api_endpoint.should eq('https://vestorly-dev.herokuapp.com/api/v1/session_management/sign_out?version=1')
21
+ end
22
+
23
+ end
24
+
25
+ describe 'sign out api' do
26
+ describe 'POST sign out' do
27
+
28
+ describe 'with valid authentication token' do
29
+
30
+ let(:authentication_token) { "eyJwYXlsb2FkIjoiNGY2NTQyYzBjZmI0OTMwMDAxMDAwMDEzIiwiY3JlYXRlZF9vbiI6MTM5NjQ2MTg2MCwic2lnbmF0dXJlIjoiUzdYV1h6d2VaNk5vZWZialoxeGFrQmNlQjM0VktEb0s1bytRTGZOckZyST0ifQ" }
31
+ let(:request_params) { { "vestorly-auth" => authentication_token } }
32
+
33
+ let(:success_response) {
34
+ {
35
+ code: 202,
36
+ message: "Successfully logged out."
37
+ }
38
+ }
39
+
40
+ subject { described_class }
41
+
42
+ before do
43
+ VCR.insert_cassette 'sign_out', :record => :new_episodes
44
+ end
45
+
46
+ after do
47
+ VCR.eject_cassette
48
+ end
49
+
50
+ it 'records the fixture' do
51
+ api_request_helper(subject, request_params)
52
+ end
53
+
54
+ it 'makes sign out request to api returns status code ok' do
55
+ sign_out_api = described_class.new(authentication_token)
56
+ sign_out_api.sign_out.should eq(success_response)
57
+ end
58
+
59
+ it 'makes sign out request with class method' do
60
+ described_class.sign_out(authentication_token).should eq(success_response)
61
+ end
62
+
63
+ end
64
+
65
+ describe 'with invalid token' do
66
+
67
+ let(:authentication_token) { "invalidTokenSomething" }
68
+ let(:request_params) { { "vestorly-auth" => authentication_token } }
69
+
70
+ let(:error_response) {
71
+ {
72
+ code: 404,
73
+ message: "Not signed in."
74
+ }
75
+ }
76
+
77
+ subject { described_class }
78
+
79
+ before do
80
+ VCR.insert_cassette 'invalid_sign_out', :record => :new_episodes
81
+ end
82
+
83
+ after do
84
+ VCR.eject_cassette
85
+ end
86
+
87
+ it 'records the fixture' do
88
+ api_request_helper(subject, request_params)
89
+ end
90
+
91
+ it 'makes sign out request with class method' do
92
+ described_class.sign_out(authentication_token).should eq(error_response)
93
+ end
94
+
95
+ end
96
+ end
97
+ end
98
+ 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 'vestorly_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "vestorly_api"
8
+ spec.version = VestorlyApi::VERSION
9
+ spec.authors = ["David Rodas"]
10
+ spec.email = ["ddreliv@gmail.com"]
11
+ spec.summary = %q{Vestorly API integration.}
12
+ spec.description = %q{The Vestorly API provides the ability for external
13
+ developers to synchronize their client data with Vestorly.
14
+ The API provides support for CRM integration, content
15
+ curation, client behavior monitoring, and compliance
16
+ monitoring software.}
17
+ spec.homepage = "https://www.vestorly.com/"
18
+ spec.license = "MIT"
19
+
20
+ spec.files = `git ls-files -z`.split("\x0")
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_development_dependency "bundler", "~> 1.5"
26
+ spec.add_development_dependency "webmock", "~>0"
27
+ spec.add_development_dependency "vcr", "~> 0"
28
+ spec.add_development_dependency "turn", "~> 0"
29
+ spec.add_development_dependency "rspec", "~> 0"
30
+
31
+ spec.add_runtime_dependency "httparty", "~> 0"
32
+ end
metadata ADDED
@@ -0,0 +1,178 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vestorly_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - David Rodas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-22 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: webmock
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: vcr
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: turn
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
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: rspec
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: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: |-
98
+ The Vestorly API provides the ability for external
99
+ developers to synchronize their client data with Vestorly.
100
+ The API provides support for CRM integration, content
101
+ curation, client behavior monitoring, and compliance
102
+ monitoring software.
103
+ email:
104
+ - ddreliv@gmail.com
105
+ executables: []
106
+ extensions: []
107
+ extra_rdoc_files: []
108
+ files:
109
+ - ".gitignore"
110
+ - ".rspec"
111
+ - Gemfile
112
+ - LICENSE.txt
113
+ - README.md
114
+ - Rakefile
115
+ - lib/vestorly_api.rb
116
+ - lib/vestorly_api/advisor_base.rb
117
+ - lib/vestorly_api/default_endpoint.rb
118
+ - lib/vestorly_api/exceptions.rb
119
+ - lib/vestorly_api/member.rb
120
+ - lib/vestorly_api/response_utils.rb
121
+ - lib/vestorly_api/sign_in.rb
122
+ - lib/vestorly_api/sign_out.rb
123
+ - lib/vestorly_api/version.rb
124
+ - spec/fixtures/vestorly_api_cassettes/advisor_posts.yml
125
+ - spec/fixtures/vestorly_api_cassettes/advisor_user_entries.yml
126
+ - spec/fixtures/vestorly_api_cassettes/fetch_members.yml
127
+ - spec/fixtures/vestorly_api_cassettes/invalid_fetch_members.yml
128
+ - spec/fixtures/vestorly_api_cassettes/invalid_sign_in.yml
129
+ - spec/fixtures/vestorly_api_cassettes/invalid_sign_out.yml
130
+ - spec/fixtures/vestorly_api_cassettes/sign_in.yml
131
+ - spec/fixtures/vestorly_api_cassettes/sign_out.yml
132
+ - spec/spec_helper.rb
133
+ - spec/vestorly_api/advisor_base_spec.rb
134
+ - spec/vestorly_api/default_endpiont_spec.rb
135
+ - spec/vestorly_api/member_spec.rb
136
+ - spec/vestorly_api/sign_in_spec.rb
137
+ - spec/vestorly_api/sign_out_spec.rb
138
+ - vestorly_api.gemspec
139
+ homepage: https://www.vestorly.com/
140
+ licenses:
141
+ - MIT
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.2.2
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Vestorly API integration.
163
+ test_files:
164
+ - spec/fixtures/vestorly_api_cassettes/advisor_posts.yml
165
+ - spec/fixtures/vestorly_api_cassettes/advisor_user_entries.yml
166
+ - spec/fixtures/vestorly_api_cassettes/fetch_members.yml
167
+ - spec/fixtures/vestorly_api_cassettes/invalid_fetch_members.yml
168
+ - spec/fixtures/vestorly_api_cassettes/invalid_sign_in.yml
169
+ - spec/fixtures/vestorly_api_cassettes/invalid_sign_out.yml
170
+ - spec/fixtures/vestorly_api_cassettes/sign_in.yml
171
+ - spec/fixtures/vestorly_api_cassettes/sign_out.yml
172
+ - spec/spec_helper.rb
173
+ - spec/vestorly_api/advisor_base_spec.rb
174
+ - spec/vestorly_api/default_endpiont_spec.rb
175
+ - spec/vestorly_api/member_spec.rb
176
+ - spec/vestorly_api/sign_in_spec.rb
177
+ - spec/vestorly_api/sign_out_spec.rb
178
+ has_rdoc: