crystal_sdk 1.0.0 → 1.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 +4 -4
- data/.gitignore +1 -0
- data/README.md +12 -7
- data/lib/crystal_sdk/profile.rb +10 -2
- data/lib/crystal_sdk/version.rb +1 -1
- data/spec/crystal_sdk/profile_spec.rb +21 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0ac7754e0ca7737a3f792fbf72b1a38fc333db61
|
4
|
+
data.tar.gz: 36981f0bda19928584e1c408afdd0e52faf329ae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4bffe97b1b4cc64e5f76b5e25e15032b58636b96bbb44d102e960dd349c8d351580d4a6485530b0a2fb13875ad1e901a188a2f876c1ca123fdbf78aaeb0104a
|
7
|
+
data.tar.gz: 6c6579a048f4c7ba398514e52507eaa98a71ff9137e5a3608255df83f5ddd3e36c1b6dc1ca6d01516a3684eaab31b6d794c78b521d6801ec3ab1e0b2d84195d3
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -17,7 +17,12 @@ CrystalSDK.key = "OrgKey"
|
|
17
17
|
begin
|
18
18
|
profile = CrystalSDK::Profile.search({
|
19
19
|
first_name: "Drew",
|
20
|
-
last_name: "D'Agostino"
|
20
|
+
last_name: "D'Agostino",
|
21
|
+
email: "drew@crystalknows.com",
|
22
|
+
company_name: "Crystal",
|
23
|
+
location: "Nashville, TN",
|
24
|
+
text_sample: "I, Drew, the founder of Crystal, think that ...",
|
25
|
+
text_type: "various"
|
21
26
|
})
|
22
27
|
|
23
28
|
print "Profile found!"
|
@@ -29,17 +34,17 @@ begin
|
|
29
34
|
|
30
35
|
print "Recommendations: #{profile.recommendations}"
|
31
36
|
|
32
|
-
rescue CrystalSDK::Profile::NotFoundError
|
37
|
+
rescue CrystalSDK::Profile::NotFoundError => e
|
33
38
|
print "No profile was found"
|
34
39
|
|
35
|
-
rescue CrystalSDK::Profile::NotFoundYetError
|
36
|
-
print "Profile search exceeded time limit"
|
40
|
+
rescue CrystalSDK::Profile::NotFoundYetError => e
|
41
|
+
print "Profile search exceeded time limit: #{e.request.id}"
|
37
42
|
|
38
|
-
rescue CrystalSDK::Profile::RateLimitHitError
|
43
|
+
rescue CrystalSDK::Profile::RateLimitHitError => e
|
39
44
|
print "The organization's API rate limit was hit"
|
40
45
|
|
41
|
-
rescue CrystalSDK::Profile::NotAuthedError
|
42
|
-
print "Org key was invalid"
|
46
|
+
rescue CrystalSDK::Profile::NotAuthedError => e
|
47
|
+
print "Org key was invalid: #{e.token}"
|
43
48
|
|
44
49
|
rescue StandardError => e
|
45
50
|
print "Unexpected error occurred: #{e}"
|
data/lib/crystal_sdk/profile.rb
CHANGED
@@ -4,10 +4,18 @@ require_relative 'profile/request'
|
|
4
4
|
module CrystalSDK
|
5
5
|
class Profile
|
6
6
|
class NotFoundError < StandardError; end
|
7
|
-
class NotAuthedError < StandardError; end
|
8
7
|
class RateLimitHitError < StandardError; end
|
9
8
|
class UnexpectedError < StandardError; end
|
10
9
|
|
10
|
+
class NotAuthedError < StandardError
|
11
|
+
attr_reader :token
|
12
|
+
|
13
|
+
def initialize(token, msg = 'Organization Token was invalid')
|
14
|
+
@token = token
|
15
|
+
super(msg)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
11
19
|
class NotFoundYetError < StandardError
|
12
20
|
attr_reader :request
|
13
21
|
|
@@ -57,7 +65,7 @@ module CrystalSDK
|
|
57
65
|
|
58
66
|
def check_for_error(resp)
|
59
67
|
raise RateLimitHitError if resp.code == '429'
|
60
|
-
raise NotAuthedError if resp.code == '401'
|
68
|
+
raise NotAuthedError.new(Base.key) if resp.code == '401'
|
61
69
|
raise NotFoundError if resp.code == '404'
|
62
70
|
end
|
63
71
|
end
|
data/lib/crystal_sdk/version.rb
CHANGED
@@ -92,6 +92,12 @@ describe CrystalSDK::Profile do
|
|
92
92
|
|
93
93
|
it 'should raise NotFoundYetError' do
|
94
94
|
expect { subject }.to raise_error(CrystalSDK::Profile::NotFoundYetError)
|
95
|
+
|
96
|
+
begin
|
97
|
+
subject
|
98
|
+
rescue CrystalSDK::Profile::NotFoundYetError => e
|
99
|
+
expect(e.request).to be(response)
|
100
|
+
end
|
95
101
|
end
|
96
102
|
end
|
97
103
|
end
|
@@ -120,8 +126,23 @@ describe CrystalSDK::Profile do
|
|
120
126
|
context '401' do
|
121
127
|
let(:resp) { double(code: '401') }
|
122
128
|
|
129
|
+
before(:each) do
|
130
|
+
@orig_key = CrystalSDK.key
|
131
|
+
CrystalSDK.key = 'SomeKey'
|
132
|
+
end
|
133
|
+
|
134
|
+
after(:each) do
|
135
|
+
CrystalSDK.key = @orig_key
|
136
|
+
end
|
137
|
+
|
123
138
|
it 'should raise NotAuthedError' do
|
124
139
|
expect { subject }.to raise_error(CrystalSDK::Profile::NotAuthedError)
|
140
|
+
|
141
|
+
begin
|
142
|
+
subject
|
143
|
+
rescue CrystalSDK::Profile::NotAuthedError => e
|
144
|
+
expect(e.token).to eql('SomeKey')
|
145
|
+
end
|
125
146
|
end
|
126
147
|
end
|
127
148
|
|