crystal_sdk 1.0.3 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6ba27b0a6417d08fd9880ceebb13a9c948687a1c
4
- data.tar.gz: 319692fbacdf2346768bac7820da9b4f5f4eeb4a
3
+ metadata.gz: 68c4c5f394f828a302f0f797109388526e207b29
4
+ data.tar.gz: 4df29ed5014ca2ff51a434d368221c8ad99ca904
5
5
  SHA512:
6
- metadata.gz: c9e85319e38fcbf762b87eecee617ae03a0adf3bb2a241292e24abc90a98fa052cc759165219a64d641ef78ac1f4a0ecff67acda949c36b0d565cfe8bc487e5f
7
- data.tar.gz: b801219d333da34f0bc7425d456d781d027295f8d49ce7e875c902809d888a96eb718d7de0547d491e9af4222201cd03daadd558fba6f84d07b16ccb53c89fba
6
+ metadata.gz: 4078fdca58cef87cd1ca92d9a6575206d12a6699c33d7126e473fc24d004c0eae1cd576481055b4d73bc8f906c8adb2277f9d0a178618d0befc1416a37047c8b
7
+ data.tar.gz: dedf3a02fa00ca650aded1cbea28aaf79f0f8d028bc591894b699007809a9df5103c2ec7cfeee838568e86c61c23014f02af93ccf2bd918da0a61fa4188c11b3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- crystal_sdk (1.0.2)
4
+ crystal_sdk (1.0.3)
5
5
  nestful (~> 1.1)
6
6
  recursive-open-struct (~> 1.0)
7
7
 
data/README.md CHANGED
@@ -1,8 +1,29 @@
1
1
  # Crystal Ruby SDK
2
2
 
3
+ [![CircleCI](https://circleci.com/gh/crystal-project-inc/ruby_sdk.svg?style=shield)](https://circleci.com/gh/crystal-project-inc/ruby_sdk)
4
+ [![Gem Version](https://badge.fury.io/rb/crystal_sdk.svg)](https://badge.fury.io/rb/crystal_sdk)
5
+
3
6
  This gem provides access to Crystal, the world's largest and most accurate personality database!
4
7
 
5
- ![Recommendations Demo](docs/recommendations.png)
8
+ ![API Summary](docs/api_summary.gif)
9
+
10
+ ## FAQ
11
+
12
+ #### Want to use our raw API?
13
+
14
+ Find the docs here:
15
+ https://developers.crystalknows.com
16
+
17
+ #### Want to learn more about us?
18
+
19
+ Visit our website: https://www.crystalknows.com
20
+
21
+ #### Need an Organization Access Token?
22
+
23
+ Get in touch with us at hello@crystalknows.com
24
+
25
+
26
+ # Usage
6
27
 
7
28
  Here's how to install it:
8
29
  ```bash
@@ -16,8 +37,10 @@ Here's how you use it:
16
37
  ```ruby
17
38
  require 'crystal_sdk'
18
39
 
19
- CrystalSDK.key = "OrgKey"
40
+ # Set your Organization Access Token
41
+ CrystalSDK.key = "OrgToken"
20
42
 
43
+ # Fetch the profile
21
44
  begin
22
45
  profile = CrystalSDK::Profile.search({
23
46
  first_name: "Drew",
@@ -32,11 +55,21 @@ begin
32
55
  print "Profile found!"
33
56
  print "First Name: #{profile.info.first_name}"
34
57
  print "Last Name: #{profile.info.last_name}"
35
- print "Predicted DISC Type: #{profile.info.disc_type}"
36
- print "Prediction Confidence: #{profile.info.confidence}"
37
- print "Personality Overview: #{profile.info.overview}"
58
+ print "Predicted DISC Type: #{profile.info.disc_scores.type}"
59
+ print "Prediction Confidence: #{profile.info.disc_scores.confidence}"
60
+ print "DISC Image: #{profile.info.disc_image}"
61
+
62
+ print "Personality Overview: #{profile.recommendations.overview}"
63
+ print "Personality Qualities: #{profile.recommendations.qualities}"
64
+
65
+ print "Likely motivations: #{profile.recommendations.motivations}"
66
+ print "Likely behaviors: #{profile.recommendations.behavior}"
38
67
 
39
- print "Recommendations: #{profile.recommendations}"
68
+ print "Tips on emailing: #{profile.recommendations.emailing}"
69
+ print "Tips on communication: #{profile.recommendations.communication}"
70
+ print "Tips on building trust: #{profile.recommendations.building_trust}"
71
+ print "Tips on selling: #{profile.recommendations.selling}"
72
+ print "Tips on working together: #{profile.recommendations.working_together}"
40
73
 
41
74
  rescue CrystalSDK::Profile::NotFoundError
42
75
  print "No profile was found"
@@ -48,7 +81,7 @@ rescue CrystalSDK::Profile::RateLimitHitError
48
81
  print "The organization's API rate limit was hit"
49
82
 
50
83
  rescue CrystalSDK::Profile::NotAuthedError => e
51
- print "Org key was invalid: #{e.token}"
84
+ print "Org token was invalid: #{e.token}"
52
85
 
53
86
  rescue StandardError => e
54
87
  print "Unexpected error occurred: #{e}"
@@ -60,7 +93,36 @@ end
60
93
 
61
94
  When requesting large amounts of profiles, or when wanting to have more fine-grained control over performance, we recommend using our asynchronous flow. It allows us to process your requests in parallel and get the information back to you more quickly. There are a couple options for using this capability.
62
95
 
63
- ### Option 1: Polling (Small Lists + Realtime Enrichment)
96
+
97
+ ### Option 1: Background Processing (Large Lists + Passive Enrichment)
98
+
99
+ Sometimes, it isn't important to have the profile information immediately. Especially when dealing with larger jobs or passive data enrichment. In that case, we allow you to save the Request ID and pull information from the request at a later time via this ID.
100
+
101
+ ```ruby
102
+ query = { first_name: "Drew", ... }
103
+
104
+ # Send the request to Crystal
105
+ profile_request = CrystalSDK::Profile::Request.from_search(query)
106
+
107
+ # Pull out the Profile Request ID (string)
108
+ profile_request_id = profile_request.id
109
+
110
+ # Save the Request ID somewhere (DB, Queue, Hard Drive..)
111
+ ...
112
+
113
+ # Later, pull up the Request ID and pull information about it
114
+ saved_req = CrystalSDK::Profile::Request.new(profile_request_id)
115
+
116
+ if saved_req.did_finish? && saved_req.did_find_profile?
117
+ profile = CrystalSDK::Profile.from_request(saved_req)
118
+ ...
119
+ end
120
+ ```
121
+
122
+ We try and store your request for a few days after the request has been started. Your Request ID should work when you try to pull information from it for at least that period of time!
123
+
124
+
125
+ ### Option 2: Polling (Small Lists + Realtime Enrichment)
64
126
  The option we use internally in the SDK, is to poll for request information periodically until a set timeout has been reached:
65
127
 
66
128
  ```ruby
@@ -69,22 +131,22 @@ PAUSE_IN_SECONDS = 3
69
131
 
70
132
  # Start the request
71
133
  query = { first_name: "Drew", ... }
72
- request = CrystalSDK::Profile::Request.from_search(query)
134
+ profile_request = CrystalSDK::Profile::Request.from_search(query)
73
135
 
74
136
  # Poll server until request finishes
75
137
  MAX_RETRIES.times do
76
-
138
+
77
139
  # If the request hasn't finished, wait and loop again
78
- unless request.did_finish?
140
+ unless profile_request.did_finish?
79
141
  sleep(PAUSE_IN_SECONDS)
80
142
  next
81
143
  end
82
144
 
83
145
  # Get profile information
84
- if request.did_find_profile?
85
- profile = Profile.from_request(request)
146
+ if profile_request.did_find_profile?
147
+ profile = CrystalSDK::Profile.from_request(profile_request)
86
148
  end
87
-
149
+
88
150
  break
89
151
  end
90
152
 
@@ -97,33 +159,6 @@ Polling can be extended to poll for multiple profiles. It gives the efficiency o
97
159
  This option is great if you want information as fast as possible while keeping open network connections and code complexity to a minimum. It is especially useful if you are requesting multiple profiles and can process the profiles one at a time, as each individual profile comes in (as opposed to waiting for all of them to come in before processing anything).
98
160
 
99
161
 
100
- ### Option 2: Background Processing (Large Lists + Passive Enrichment)
101
-
102
- Sometimes, it isn't important to have the profile information immediately. Especially when dealing with larger jobs or passive data enrichment. In that case, we allow you to save the Request ID and pull information from the request at a later time via this ID.
103
-
104
- ```ruby
105
-
106
- # Send the request to Crystal
107
- profile_request = CrystalSDK::Profile::Request.from_search(query)
108
-
109
- # Pull out the Profile Request ID (string)
110
- profile_request_id = profile_request.id
111
-
112
- # Save the Request ID somewhere (to a database or background job, for example)
113
- ...
114
-
115
- # Later, pull up the Request ID and pull information about it
116
- backgrounded_request = CrystalSDK::Profile::Request.new(profile_request_id)
117
-
118
- if backgrounded_request.did_finish? && backgrounded_request.did_find_profile?
119
- profile = backgrounded_request.profile
120
- ...
121
- end
122
- ```
123
-
124
- We try and store your request for a few days after the request has been started. Your Request ID should work when you try to pull information from it for at least that period of time!
125
-
126
-
127
162
  ## Contributing
128
163
 
129
164
  - Clone the repository:
Binary file
@@ -13,7 +13,7 @@ module CrystalSDK
13
13
  class << self
14
14
  def from_search(query)
15
15
  begin
16
- resp = Api.make_request(:post, 'profile_search/async', params: query)
16
+ resp = Api.make_request(:post, 'profiles/async', params: query)
17
17
  rescue Nestful::ResponseError => e
18
18
  check_for_error(e.response)
19
19
  raise e
@@ -34,7 +34,7 @@ module CrystalSDK
34
34
  return @cached_data if @cached_data
35
35
 
36
36
  begin
37
- resp = Api.make_request(:get, "results/#{@id}")
37
+ resp = Api.make_request(:get, "profiles/results/#{@id}")
38
38
  rescue Nestful::ResponseError => e
39
39
  Request.check_for_error(e.response)
40
40
  raise e
@@ -66,7 +66,8 @@ module CrystalSDK
66
66
  return false unless did_finish? && fetch_status == 'complete'
67
67
 
68
68
  info = fetch_request_info
69
- !info[:data][:info][:error]
69
+ print info
70
+ !info[:info][:error]
70
71
  rescue Profile::NotFoundError
71
72
  false
72
73
  end
@@ -75,8 +76,8 @@ module CrystalSDK
75
76
  return nil unless did_find_profile?
76
77
 
77
78
  req_info = fetch_request_info
78
- profile_info = RecursiveOpenStruct.new(req_info[:data][:info])
79
- recommendations = RecursiveOpenStruct.new(req_info[:data][:recommendations])
79
+ profile_info = RecursiveOpenStruct.new(req_info[:info])
80
+ recommendations = RecursiveOpenStruct.new(req_info[:recommendations])
80
81
 
81
82
  { info: profile_info, recommendations: recommendations }
82
83
  end
@@ -1,3 +1,3 @@
1
1
  module CrystalSDK
2
- VERSION = '1.0.3'.freeze
2
+ VERSION = '1.1.0'.freeze
3
3
  end
@@ -12,7 +12,7 @@ describe CrystalSDK::Profile::Request do
12
12
  subject { CrystalSDK::Profile::Request.from_search(query) }
13
13
  let(:query) { { first_name: 'Test', last_name: 'Test' } }
14
14
  let(:request_type) { :post }
15
- let(:endpoint) { 'profile_search/async' }
15
+ let(:endpoint) { 'profiles/async' }
16
16
 
17
17
  context 'CrystalSDK::Api raises exception' do
18
18
  it 'should not suppress it' do
@@ -59,7 +59,7 @@ describe CrystalSDK::Profile::Request do
59
59
  describe '#fetch_request_info' do
60
60
  subject { CrystalSDK::Profile::Request.new('my_id').fetch_request_info() }
61
61
  let(:request_type) { :get }
62
- let(:endpoint) { 'results/my_id' }
62
+ let(:endpoint) { 'profiles/results/my_id' }
63
63
 
64
64
  context 'CrystalSDK::Api raises exception' do
65
65
  it 'should not suppress it' do
@@ -247,7 +247,7 @@ describe CrystalSDK::Profile::Request do
247
247
  context '#fetch_request_info error is not nil' do
248
248
  before(:each) do
249
249
  allow(request).to receive(:fetch_request_info).and_return({
250
- data: { info: { error: 'error' } }
250
+ info: { error: 'error' }
251
251
  })
252
252
  end
253
253
 
@@ -257,7 +257,7 @@ describe CrystalSDK::Profile::Request do
257
257
  context '#fetch_request_info error is nil' do
258
258
  before(:each) do
259
259
  allow(request).to receive(:fetch_request_info).and_return({
260
- data: { info: { error: nil } }
260
+ info: { error: nil }
261
261
  })
262
262
  end
263
263
 
@@ -283,19 +283,17 @@ describe CrystalSDK::Profile::Request do
283
283
  before(:each) do
284
284
  allow(request).to receive(:did_find_profile?).and_return(true)
285
285
  allow(request).to receive(:fetch_request_info).and_return({
286
- data: {
287
286
  info: {
288
- some_info: 'some_info',
289
- deep_info: {
290
- info: 'deep_info'
291
- }
292
- },
293
-
294
- recommendations: {
295
- some_recs: 'some_recs',
296
- deep_recs: {
297
- recs: 'deep_recs'
298
- }
287
+ some_info: 'some_info',
288
+ deep_info: {
289
+ info: 'deep_info'
290
+ }
291
+ },
292
+
293
+ recommendations: {
294
+ some_recs: 'some_recs',
295
+ deep_recs: {
296
+ recs: 'deep_recs'
299
297
  }
300
298
  }
301
299
  })
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crystal_sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cory Finger
@@ -82,7 +82,7 @@ files:
82
82
  - README.md
83
83
  - Rakefile
84
84
  - crystal_sdk.gemspec
85
- - docs/recommendations.png
85
+ - docs/api_summary.gif
86
86
  - lib/crystal_sdk.rb
87
87
  - lib/crystal_sdk/api.rb
88
88
  - lib/crystal_sdk/base.rb
Binary file