crowdskout 0.1.2 → 0.1.3
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/crowdskout.gemspec +3 -3
- data/lib/crowdskout/api.rb +19 -19
- data/lib/crowdskout/services/attribute_service.rb +58 -60
- data/lib/crowdskout/services/base_service.rb +39 -36
- data/lib/crowdskout/services/field_service.rb +13 -16
- data/lib/crowdskout/services/profile_service.rb +102 -105
- data/lib/crowdskout/services/quartermaster_service.rb +7 -10
- data/lib/crowdskout/version.rb +1 -1
- data/spec/crowdskout/services/attribute_service_spec.rb +6 -6
- data/spec/crowdskout/services/field_service_spec.rb +2 -2
- data/spec/crowdskout/services/profile_service_spec.rb +8 -8
- data/spec/crowdskout/services/quartermaster_service_spec.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33c5a1c083c3e9f945343fcdff2642adbeeef50f
|
4
|
+
data.tar.gz: e8b36820423e9fff116715c91de4ccab284b85c0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb066cd2ad5f866565544a17ce96beff1e7e059261a812876875dad1aa78d75dca7be8e1c1297686988744023f1fae3584621efa2869db9b5998eaf4af391475
|
7
|
+
data.tar.gz: cf490e66c32d7f02fdf35fb80dafc92c7613166327f5cf6d8d5232e605743ddc878a3a65dbdac035013531bd3d75937ddc17e427395deffa4cfbb2707fb9c77e
|
data/crowdskout.gemspec
CHANGED
@@ -5,7 +5,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "crowdskout"
|
8
|
-
s.version = '0.1.
|
8
|
+
s.version = '0.1.3'
|
9
9
|
s.platform = Gem::Platform::RUBY
|
10
10
|
s.authors = ["Crowdskout", "Revv","Kyle Schutt"]
|
11
11
|
s.homepage = "https://github.com/revvco/crowdskout"
|
@@ -23,9 +23,9 @@ Gem::Specification.new do |s|
|
|
23
23
|
s.executables = []
|
24
24
|
s.require_paths = [ "lib" ]
|
25
25
|
s.test_files = Dir['spec/**/*_spec.rb']
|
26
|
-
|
26
|
+
|
27
27
|
s.add_runtime_dependency("rest-client", '< 4.0', '>= 1.6.7')
|
28
28
|
s.add_runtime_dependency("json", '~> 1.8', '>= 1.8.1')
|
29
29
|
s.add_runtime_dependency('mime-types', '< 4.0', '>= 1.25.1')
|
30
30
|
s.add_development_dependency("rspec", '~> 2.14')
|
31
|
-
end
|
31
|
+
end
|
data/lib/crowdskout/api.rb
CHANGED
@@ -10,62 +10,62 @@ module Crowdskout
|
|
10
10
|
# @param [String] api_key - Crowdskout API Key
|
11
11
|
# @param [String] access_token - Crowdskout OAuth2 access token
|
12
12
|
# @return
|
13
|
-
def initialize(api_key = nil, access_token = nil)
|
14
|
-
|
15
|
-
|
16
|
-
if
|
13
|
+
def initialize(api_key = nil, access_token = nil))
|
14
|
+
@api_key = api_key || Util::Config.get('auth.api_key')
|
15
|
+
@access_token = access_token
|
16
|
+
if @api_key.nil? || @api_key == ''
|
17
17
|
raise ArgumentError.new(Util::Config.get('errors.api_key_missing'))
|
18
18
|
end
|
19
|
-
if
|
19
|
+
if @access_token.nil? || @access_token == ''
|
20
20
|
raise ArgumentError.new(Util::Config.get('errors.access_token_missing'))
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
# Profile Service Methods
|
25
25
|
def get_profile(profile_id, collections)
|
26
|
-
Services::ProfileService.get_profile(profile_id, collections)
|
26
|
+
Services::ProfileService.new(api_key, access_token).get_profile(profile_id, collections)
|
27
27
|
end
|
28
28
|
def create_profile(profile)
|
29
|
-
Services::ProfileService.create_profile(profile)
|
29
|
+
Services::ProfileService.new(api_key, access_token).create_profile(profile)
|
30
30
|
end
|
31
31
|
def create_profiles_bulk(profiles)
|
32
|
-
Services::ProfileService.create_profiles_bulk(profiles)
|
32
|
+
Services::ProfileService.new(api_key, access_token).create_profiles_bulk(profiles)
|
33
33
|
end
|
34
34
|
def update_profile(profile)
|
35
|
-
Services::ProfileService.update_profile(profile)
|
35
|
+
Services::ProfileService.new(api_key, access_token).update_profile(profile)
|
36
36
|
end
|
37
37
|
def update_profiles_bulk(profiles)
|
38
|
-
Services::ProfileService.update_profiles_bulk(profiles)
|
38
|
+
Services::ProfileService.new(api_key, access_token).update_profiles_bulk(profiles)
|
39
39
|
end
|
40
40
|
def check_for_non_match(profile)
|
41
|
-
Services::ProfileService.check_for_non_match(profile)
|
41
|
+
Services::ProfileService.new(api_key, access_token).check_for_non_match(profile)
|
42
42
|
end
|
43
43
|
|
44
44
|
# Fields Service Methods
|
45
45
|
def get_options_for_a_field(field_name, params = {})
|
46
|
-
Services::FieldService.get_options_for_a_field(field_name, params)
|
46
|
+
Services::FieldService.new(api_key, access_token).get_options_for_a_field(field_name, params)
|
47
47
|
end
|
48
48
|
|
49
49
|
# Attribute Service Methods
|
50
50
|
def get_attributes(params = {})
|
51
|
-
Services::AttributeService.get_attributes(params)
|
51
|
+
Services::AttributeService.new(api_key, access_token).get_attributes(params)
|
52
52
|
end
|
53
53
|
def get_attribute(attribute_id, params = {})
|
54
|
-
Services::AttributeService.get_attribute(attribute_id)
|
54
|
+
Services::AttributeService.new(api_key, access_token).get_attribute(attribute_id)
|
55
55
|
end
|
56
56
|
def create_attribute(name, type, options = nil)
|
57
|
-
Services::AttributeService.create_attribute(name, type, options)
|
57
|
+
Services::AttributeService.new(api_key, access_token).create_attribute(name, type, options)
|
58
58
|
end
|
59
59
|
def update_attribute(attribute_id, params = {})
|
60
|
-
Services::AttributeService.update_attribute(attribute_id, params)
|
60
|
+
Services::AttributeService.new(api_key, access_token).update_attribute(attribute_id, params)
|
61
61
|
end
|
62
62
|
def delete_attribute(attribute_id)
|
63
|
-
Services::AttributeService.delete_attribute(attribute_id)
|
63
|
+
Services::AttributeService.new(api_key, access_token).delete_attribute(attribute_id)
|
64
64
|
end
|
65
65
|
|
66
66
|
# Quartermaster Service Methods
|
67
67
|
def tracking_code
|
68
|
-
Services::QuartermasterService.tracking_code
|
68
|
+
Services::QuartermasterService.new(api_key, access_token).tracking_code
|
69
69
|
end
|
70
70
|
end
|
71
|
-
end
|
71
|
+
end
|
@@ -7,74 +7,72 @@
|
|
7
7
|
module Crowdskout
|
8
8
|
module Services
|
9
9
|
class AttributeService < BaseService
|
10
|
-
class << self
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
11
|
+
# More info - http://docs.crowdskout.com/api/#get-all-attributes
|
12
|
+
# @param [Hash] params - query parameters
|
13
|
+
# @return [ResultSet] set of Components::Attributes
|
14
|
+
def get_attributes(params = {})
|
15
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.attributes')
|
16
|
+
url = build_url(url, params)
|
18
17
|
|
19
|
-
|
20
|
-
|
18
|
+
response = RestClient.get(url, get_headers())
|
19
|
+
body = JSON.parse(response.body)
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
attributes = []
|
22
|
+
body['data']['list'].each do |attribute|
|
23
|
+
attributes << Components::Attribute.create(attribute)
|
24
|
+
end if body['data']["total"] > 0
|
26
25
|
|
27
|
-
|
28
|
-
|
26
|
+
Components::ResultSet.new(attributes, body['messages'])
|
27
|
+
end
|
29
28
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
29
|
+
# more info - http://docs.crowdskout.com/api/#get-an-attribute-by-id
|
30
|
+
# @param [Integer] attribute_id - the id of the attribute to fetch
|
31
|
+
# @param [Hash] params - query parameters
|
32
|
+
# @return [Attribute]
|
33
|
+
def get_attribute(attribute_id, params = {})
|
34
|
+
raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil?
|
35
|
+
url = Util::Config.get('endpoints.base_url') +
|
36
|
+
sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id)
|
37
|
+
url = build_url(url, params)
|
38
|
+
response = RestClient.get(url, get_headers())
|
39
|
+
Components::Attribute.create(JSON.parse(response.body)["data"])
|
40
|
+
end
|
42
41
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
42
|
+
# more info - http://docs.crowdskout.com/api/#create-an-attribute
|
43
|
+
# @param [Attribute] attribute - attribute object to add to Crowdskout
|
44
|
+
# @return [Attribute]
|
45
|
+
def create_attribute(new_attribute)
|
46
|
+
raise Exceptions::ServiceException, "Attribute must not be nil" if new_attribute.nil?
|
47
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.attribute')
|
48
|
+
url = build_url(url)
|
49
|
+
payload = new_attribute.to_json
|
50
|
+
response = RestClient.post(url, payload, get_headers())
|
51
|
+
Components::Attribute.create(JSON.parse(response.body)["data"])
|
52
|
+
end
|
54
53
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
54
|
+
# more info - http://docs.crowdskout.com/api/#update-an-attribute
|
55
|
+
# @param [Integer] attribute_id - the id of the attribute to update
|
56
|
+
# @param [Hash] params - query parameters
|
57
|
+
# @return [Attribute]
|
58
|
+
def update_attribute(attribute_id, params = {})
|
59
|
+
raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil?
|
60
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id)
|
61
|
+
url = build_url(url)
|
62
|
+
response = RestClient.put(url, params, get_headers())
|
63
|
+
Components::Attribute.create(JSON.parse(response.body)["data"])
|
64
|
+
end
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
end
|
66
|
+
# more info - http://docs.crowdskout.com/api/#delete-an-attribute
|
67
|
+
# @param [Integer] attribute_id - the id of the attribute to update
|
68
|
+
# @return [boolean]
|
69
|
+
def delete_attribute(attribute_id)
|
70
|
+
raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil?
|
71
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id)
|
72
|
+
url = build_url(url)
|
73
|
+
response = RestClient.delete(url, get_headers())
|
74
|
+
response.code == 204
|
77
75
|
end
|
78
76
|
end
|
79
77
|
end
|
80
|
-
end
|
78
|
+
end
|
@@ -7,50 +7,53 @@
|
|
7
7
|
module Crowdskout
|
8
8
|
module Services
|
9
9
|
class BaseService
|
10
|
-
|
11
|
-
attr_accessor :api_key, :access_token
|
10
|
+
attr_accessor :api_key, :access_token
|
12
11
|
|
13
|
-
|
12
|
+
attr_accessor :api_key
|
13
|
+
def initialize(api_key = nil, access_token = nil)
|
14
|
+
@api_key = api_key
|
15
|
+
@access_token = access_token
|
16
|
+
end
|
17
|
+
protected
|
14
18
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
19
|
+
# Return required headers for making an http request with Crowdskout
|
20
|
+
# @param [String] content_type - The MIME type of the body of the request, default is 'application/json'
|
21
|
+
# @return [Hash] - authorization headers
|
22
|
+
def get_headers(content_type = 'application/json')
|
23
|
+
{
|
24
|
+
:content_type => content_type,
|
25
|
+
:accept => 'application/json',
|
26
|
+
:authorization => "Bearer #{@access_token}",
|
27
|
+
:user_agent => "AppConnect Ruby SDK v#{Crowdskout::VERSION} (#{RUBY_DESCRIPTION})",
|
28
|
+
:x_ctct_request_source => "sdk.ruby.#{Crowdskout::VERSION}"
|
29
|
+
}
|
30
|
+
end
|
27
31
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
32
|
+
# Build a url from the base url and query parameters hash. Query parameters
|
33
|
+
# should not be URL encoded because this method will handle that
|
34
|
+
# @param [String] url - The base url
|
35
|
+
# @param [Hash] params - A hash with query parameters
|
36
|
+
# @return [String] - the url with query parameters hash
|
37
|
+
def build_url(url, params = nil)
|
38
|
+
if params.respond_to? :each
|
39
|
+
params.each do |key, value|
|
40
|
+
# Convert dates to CC date format
|
41
|
+
if value.respond_to? :iso8601
|
42
|
+
params[key] = value.iso8601
|
43
|
+
end
|
40
44
|
|
41
|
-
|
42
|
-
|
43
|
-
end
|
45
|
+
if key.to_s == 'next' && value.match(/^.*?next=(.*)$/)
|
46
|
+
params[key] = $1
|
44
47
|
end
|
45
|
-
else
|
46
|
-
params ||= {}
|
47
48
|
end
|
48
|
-
|
49
|
-
params
|
50
|
-
url += '?' + Util::Helpers.http_build_query(params)
|
49
|
+
else
|
50
|
+
params ||= {}
|
51
51
|
end
|
52
52
|
|
53
|
+
params['api_key'] = @api_key
|
54
|
+
url += '?' + Util::Helpers.http_build_query(params)
|
53
55
|
end
|
56
|
+
|
54
57
|
end
|
55
58
|
end
|
56
|
-
end
|
59
|
+
end
|
@@ -7,22 +7,19 @@
|
|
7
7
|
module Crowdskout
|
8
8
|
module Services
|
9
9
|
class FieldService < BaseService
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
response = RestClient.get(url, get_headers())
|
23
|
-
Components::FieldOptions.create(JSON.parse(response.body)["data"])
|
24
|
-
end
|
10
|
+
# more info - http://docs.crowdskout.com/api/#get-the-options-for-a-field
|
11
|
+
# Get the options for a field
|
12
|
+
# @param [String] field_name - the name of the field
|
13
|
+
# @param [Hash] params - A hash with query parameters
|
14
|
+
# @return [FieldOptions] - the field options
|
15
|
+
def get_options_for_a_field(field_name, params = {})
|
16
|
+
raise Exceptions::ServiceException, "Field name is required." if field_name.nil?
|
17
|
+
url = Util::Config.get('endpoints.base_url') +
|
18
|
+
sprintf(Util::Config.get('endpoints.fields_options'), field_name)
|
19
|
+
url = build_url(url, params)
|
20
|
+
response = RestClient.get(url, get_headers())
|
21
|
+
Components::FieldOptions.create(JSON.parse(response.body)["data"])
|
25
22
|
end
|
26
23
|
end
|
27
24
|
end
|
28
|
-
end
|
25
|
+
end
|
@@ -7,121 +7,118 @@
|
|
7
7
|
module Crowdskout
|
8
8
|
module Services
|
9
9
|
class ProfileService < BaseService
|
10
|
-
|
10
|
+
# more info - http://docs.crowdskout.com/api/#get-a-profile-by-id
|
11
|
+
# Get a profile based on the collections provided
|
12
|
+
# @param [Integer] profile_id - the id of the profile
|
13
|
+
# @param [String] collections - A csv of the requested collections
|
14
|
+
# @return [Profile] - the profile object
|
15
|
+
def get_profile(profile_id, collections)
|
16
|
+
raise Exceptions::ServiceException, "Profile ID is required." if profile_id.nil?
|
17
|
+
raise Exceptions::ServiceException, "A comma-deliminted list of collections is required." if collections.nil?
|
18
|
+
params = {
|
19
|
+
collections: collections
|
20
|
+
}
|
21
|
+
url = Util::Config.get('endpoints.base_url') +
|
22
|
+
sprintf(Util::Config.get('endpoints.crud_profile'), profile_id)
|
23
|
+
url = build_url(url, params)
|
11
24
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# @param [String] collections - A csv of the requested collections
|
16
|
-
# @return [Profile] - the profile object
|
17
|
-
def get_profile(profile_id, collections)
|
18
|
-
raise Exceptions::ServiceException, "Profile ID is required." if profile_id.nil?
|
19
|
-
raise Exceptions::ServiceException, "A comma-deliminted list of collections is required." if collections.nil?
|
20
|
-
params = {
|
21
|
-
collections: collections
|
22
|
-
}
|
23
|
-
url = Util::Config.get('endpoints.base_url') +
|
24
|
-
sprintf(Util::Config.get('endpoints.crud_profile'), profile_id)
|
25
|
-
url = build_url(url, params)
|
26
|
-
|
27
|
-
response = RestClient.get(url, get_headers())
|
28
|
-
Components::Profile.create(JSON.parse(response.body)["data"])
|
29
|
-
end
|
25
|
+
response = RestClient.get(url, get_headers())
|
26
|
+
Components::Profile.create(JSON.parse(response.body)["data"])
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
29
|
+
# more info - http://docs.crowdskout.com/api/#create-a-profile
|
30
|
+
# Create a new profile
|
31
|
+
# @param [Profile] profile - the new profile object to add to Crowdskout
|
32
|
+
# @param [Hash] params - A hash with query parameters
|
33
|
+
# @return [Profile] - the profile object
|
34
|
+
def create_profile(profile)
|
35
|
+
raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
|
36
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile')
|
37
|
+
url = build_url(url)
|
38
|
+
payload = {
|
39
|
+
profile: profile.to_hash
|
40
|
+
}.to_json
|
41
|
+
response = RestClient.post(url, payload, get_headers())
|
42
|
+
Components::Profile.create(JSON.parse(response.body)["data"])
|
43
|
+
end
|
46
44
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
45
|
+
# more info - http://docs.crowdskout.com/api/#create-many-profiles
|
46
|
+
# Create a bunch of new profiles
|
47
|
+
# @param [Array<Profile>] profiles - an array of profile to bulk add
|
48
|
+
# @param [Hash] params - A hash with query parameters
|
49
|
+
# @return [ResultSet] - the results set as an enumeration with profiles
|
50
|
+
def create_profiles_bulk(profiles)
|
51
|
+
raise Exceptions::ServiceException, "Must be an array of profiles." if profiles.nil? || !profiles.is_a?(Array)
|
52
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile_bulk')
|
53
|
+
url = build_url(url)
|
54
|
+
payload = {
|
55
|
+
profiles: profiles.collect(&:to_hash)
|
56
|
+
}.to_json
|
57
|
+
response = RestClient.post(url, payload, get_headers())
|
58
|
+
body = JSON.parse(response.body)
|
61
59
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
60
|
+
profiles = []
|
61
|
+
body['data'].each do |profile|
|
62
|
+
profiles << Components::Profile.create(profile)
|
63
|
+
end if body['data'].count > 0
|
66
64
|
|
67
|
-
|
68
|
-
|
65
|
+
Components::ResultSet.new(profiles, body['messages'])
|
66
|
+
end
|
69
67
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
68
|
+
# more info - http://docs.crowdskout.com/api/#update-a-profile-by-id
|
69
|
+
# Update the given profile
|
70
|
+
# @param [Profile] profile - the profile to update
|
71
|
+
# @return [Profile] - the profile object
|
72
|
+
def update_profile(profile)
|
73
|
+
raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
|
74
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_profile'), profile.id)
|
75
|
+
url = build_url(url)
|
76
|
+
payload = {
|
77
|
+
profile: profile.to_hash
|
78
|
+
}.to_json
|
79
|
+
response = RestClient.put(url, payload, get_headers())
|
80
|
+
Components::Profile.create(JSON.parse(response.body)["data"])
|
81
|
+
end
|
84
82
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
83
|
+
# more info - http://docs.crowdskout.com/api/#update-many-profiles
|
84
|
+
# Update a bunch of profiles
|
85
|
+
# @param [Array<Profile>] profiles - an array of profile to bulk add
|
86
|
+
# @return [ResultSet] - the results set as an enumeration with profiles
|
87
|
+
def update_profiles_bulk(profiles)
|
88
|
+
raise Exceptions::ServiceException, "Must be an array of profiles." if profiles.nil? || !profiles.is_a?(Array)
|
89
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile_bulk')
|
90
|
+
url = build_url(url)
|
91
|
+
payload = {
|
92
|
+
profiles: profiles.collect(&:to_hash)
|
93
|
+
}.to_json
|
94
|
+
response = RestClient.put(url, payload, get_headers())
|
95
|
+
body = JSON.parse(response.body)
|
98
96
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
97
|
+
profiles = []
|
98
|
+
body['data'].each do |profile|
|
99
|
+
profiles << Components::Profile.create(profile)
|
100
|
+
end if body['data'].count > 0
|
103
101
|
|
104
|
-
|
105
|
-
|
102
|
+
Components::ResultSet.new(profiles, body['messages'])
|
103
|
+
end
|
106
104
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
end
|
105
|
+
# more info - https://docs.crowdskout.com/api/#check-for-a-non-match
|
106
|
+
#
|
107
|
+
# Check for a non-match. The endpoints returns true if the given Profile object is definitely NOT a match.
|
108
|
+
# That means that the ID given in the Profile object does not match the Profile data.
|
109
|
+
#
|
110
|
+
# @param [Profile] profile - profile to check for non-match
|
111
|
+
# @return [boolean] - returns true if it is a non-match, false in all other scenarios
|
112
|
+
def check_for_non_match(profile)
|
113
|
+
raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
|
114
|
+
url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.check_for_non_match'), profile.id)
|
115
|
+
url = build_url(url)
|
116
|
+
payload = {
|
117
|
+
profile: profile.to_hash
|
118
|
+
}.to_json
|
119
|
+
response = RestClient.post(url, payload, get_headers())
|
120
|
+
JSON.parse(response.body)["data"]
|
124
121
|
end
|
125
122
|
end
|
126
123
|
end
|
127
|
-
end
|
124
|
+
end
|
@@ -7,17 +7,14 @@
|
|
7
7
|
module Crowdskout
|
8
8
|
module Services
|
9
9
|
class QuartermasterService < BaseService
|
10
|
-
|
10
|
+
# More info - to get the tracking codes for CrowdSkout
|
11
|
+
# @return [Components::TrackingCode] Components::TrackingCode
|
12
|
+
def tracking_code
|
13
|
+
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.tracking')
|
11
14
|
|
12
|
-
|
13
|
-
|
14
|
-
def tracking_code
|
15
|
-
url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.tracking')
|
16
|
-
|
17
|
-
response = RestClient.get(url, get_headers())
|
18
|
-
Components::TrackingCode.create(JSON.parse(response.body)["data"])
|
19
|
-
end
|
15
|
+
response = RestClient.get(url, get_headers())
|
16
|
+
Components::TrackingCode.create(JSON.parse(response.body)["data"])
|
20
17
|
end
|
21
18
|
end
|
22
19
|
end
|
23
|
-
end
|
20
|
+
end
|
data/lib/crowdskout/version.rb
CHANGED
@@ -18,7 +18,7 @@ describe Crowdskout::Services::AttributeService do
|
|
18
18
|
|
19
19
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
20
20
|
RestClient.stub(:get).and_return(response)
|
21
|
-
attributes = Crowdskout::Services::AttributeService.get_attributes()
|
21
|
+
attributes = Crowdskout::Services::AttributeService.new('api_key', 'access_token').get_attributes()
|
22
22
|
attribute = attributes.results[0]
|
23
23
|
|
24
24
|
attributes.should be_kind_of(Crowdskout::Components::ResultSet)
|
@@ -33,7 +33,7 @@ describe Crowdskout::Services::AttributeService do
|
|
33
33
|
|
34
34
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
35
35
|
RestClient.stub(:get).and_return(response)
|
36
|
-
attribute = Crowdskout::Services::AttributeService.get_attribute(1)
|
36
|
+
attribute = Crowdskout::Services::AttributeService.new('api_key', 'access_token').get_attribute(1)
|
37
37
|
|
38
38
|
attribute.should be_kind_of(Crowdskout::Components::Attribute)
|
39
39
|
end
|
@@ -47,7 +47,7 @@ describe Crowdskout::Services::AttributeService do
|
|
47
47
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
48
48
|
RestClient.stub(:post).and_return(response)
|
49
49
|
new_attribute = Crowdskout::Components::Attribute.create(JSON.parse(json))
|
50
|
-
attribute = Crowdskout::Services::AttributeService.create_attribute(new_attribute)
|
50
|
+
attribute = Crowdskout::Services::AttributeService.new('api_key', 'access_token').create_attribute(new_attribute)
|
51
51
|
|
52
52
|
attribute.should be_kind_of(Crowdskout::Components::Attribute)
|
53
53
|
attribute.type.should eq('Radio')
|
@@ -62,7 +62,7 @@ describe Crowdskout::Services::AttributeService do
|
|
62
62
|
response = RestClient::Response.create('', net_http_resp, @request)
|
63
63
|
RestClient.stub(:delete).and_return(response)
|
64
64
|
|
65
|
-
result = Crowdskout::Services::AttributeService.delete_attribute(attribute_id)
|
65
|
+
result = Crowdskout::Services::AttributeService.new('api_key', 'access_token').delete_attribute(attribute_id)
|
66
66
|
result.should be true
|
67
67
|
end
|
68
68
|
end
|
@@ -75,10 +75,10 @@ describe Crowdskout::Services::AttributeService do
|
|
75
75
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
76
76
|
RestClient.stub(:put).and_return(response)
|
77
77
|
attribute = Crowdskout::Components::Attribute.create(JSON.parse(json))
|
78
|
-
result = Crowdskout::Services::AttributeService.update_attribute(attribute)
|
78
|
+
result = Crowdskout::Services::AttributeService.new('api_key', 'access_token').update_attribute(attribute)
|
79
79
|
|
80
80
|
result.should be_kind_of(Crowdskout::Components::Attribute)
|
81
81
|
result.type.should eq('Radio')
|
82
82
|
end
|
83
83
|
end
|
84
|
-
end
|
84
|
+
end
|
@@ -18,11 +18,11 @@ describe Crowdskout::Services::FieldService do
|
|
18
18
|
|
19
19
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
20
20
|
RestClient.stub(:get).and_return(response)
|
21
|
-
field = Crowdskout::Services::FieldService.get_options_for_a_field("AddressCity")
|
21
|
+
field = Crowdskout::Services::FieldService.new('api_key', 'access_token').get_options_for_a_field("AddressCity")
|
22
22
|
|
23
23
|
field.should be_kind_of(Crowdskout::Components::FieldOptions)
|
24
24
|
field.collection.should eq "PhysicalAddresses"
|
25
25
|
field.options[0].value.should eq "Lisbon"
|
26
26
|
end
|
27
27
|
end
|
28
|
-
end
|
28
|
+
end
|
@@ -18,7 +18,7 @@ describe Crowdskout::Services::ProfileService do
|
|
18
18
|
|
19
19
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
20
20
|
RestClient.stub(:get).and_return(response)
|
21
|
-
profile = Crowdskout::Services::ProfileService.get_profile(1, "Names,Genders")
|
21
|
+
profile = Crowdskout::Services::ProfileService.new('api_key', 'access_token').get_profile(1, "Names,Genders")
|
22
22
|
|
23
23
|
profile.should be_kind_of(Crowdskout::Components::Profile)
|
24
24
|
profile.collections[1].should be_kind_of(Crowdskout::Components::Collection)
|
@@ -43,7 +43,7 @@ describe Crowdskout::Services::ProfileService do
|
|
43
43
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
44
44
|
RestClient.stub(:post).and_return(response)
|
45
45
|
new_profile = Crowdskout::Components::Profile.create(JSON.parse(json)["data"])
|
46
|
-
profile = Crowdskout::Services::ProfileService.create_profile(new_profile)
|
46
|
+
profile = Crowdskout::Services::ProfileService.new('api_key', 'access_token').create_profile(new_profile)
|
47
47
|
|
48
48
|
profile.should be_kind_of(Crowdskout::Components::Profile)
|
49
49
|
profile.collections[1].should be_kind_of(Crowdskout::Components::Collection)
|
@@ -72,7 +72,7 @@ describe Crowdskout::Services::ProfileService do
|
|
72
72
|
body['data'].each do |profile|
|
73
73
|
profiles << Crowdskout::Components::Profile.create(profile)
|
74
74
|
end if body['data'].count > 0
|
75
|
-
profiles = Crowdskout::Services::ProfileService.create_profiles_bulk(profiles)
|
75
|
+
profiles = Crowdskout::Services::ProfileService.new('api_key', 'access_token').create_profiles_bulk(profiles)
|
76
76
|
profile = profiles.results[0]
|
77
77
|
|
78
78
|
profiles.should be_kind_of(Crowdskout::Components::ResultSet)
|
@@ -97,7 +97,7 @@ describe Crowdskout::Services::ProfileService do
|
|
97
97
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
98
98
|
RestClient.stub(:put).and_return(response)
|
99
99
|
profile = Crowdskout::Components::Profile.create(JSON.parse(json)["data"])
|
100
|
-
result = Crowdskout::Services::ProfileService.update_profile(profile)
|
100
|
+
result = Crowdskout::Services::ProfileService.new('api_key', 'access_token').update_profile(profile)
|
101
101
|
|
102
102
|
result.should be_kind_of(Crowdskout::Components::Profile)
|
103
103
|
result.collections[1].should be_kind_of(Crowdskout::Components::Collection)
|
@@ -126,7 +126,7 @@ describe Crowdskout::Services::ProfileService do
|
|
126
126
|
body['data'].each do |profile|
|
127
127
|
profiles << Crowdskout::Components::Profile.create(profile)
|
128
128
|
end if body['data'].count > 0
|
129
|
-
profiles = Crowdskout::Services::ProfileService.update_profiles_bulk(profiles)
|
129
|
+
profiles = Crowdskout::Services::ProfileService.new('api_key', 'access_token').update_profiles_bulk(profiles)
|
130
130
|
profile = profiles.results[0]
|
131
131
|
|
132
132
|
profiles.should be_kind_of(Crowdskout::Components::ResultSet)
|
@@ -150,7 +150,7 @@ describe Crowdskout::Services::ProfileService do
|
|
150
150
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
151
151
|
RestClient.stub(:post).and_return(response)
|
152
152
|
profile = Crowdskout::Components::Profile.create(JSON.parse(load_file('profile_response.json'))["data"])
|
153
|
-
non_match_response = Crowdskout::Services::ProfileService.check_for_non_match(profile)
|
153
|
+
non_match_response = Crowdskout::Services::ProfileService.new('api_key', 'access_token').check_for_non_match(profile)
|
154
154
|
|
155
155
|
non_match_response.should eq true
|
156
156
|
end
|
@@ -162,9 +162,9 @@ describe Crowdskout::Services::ProfileService do
|
|
162
162
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
163
163
|
RestClient.stub(:post).and_return(response)
|
164
164
|
profile = Crowdskout::Components::Profile.create(JSON.parse(load_file('profile_response.json'))["data"])
|
165
|
-
non_match_response = Crowdskout::Services::ProfileService.check_for_non_match(profile)
|
165
|
+
non_match_response = Crowdskout::Services::ProfileService.new('api_key', 'access_token').check_for_non_match(profile)
|
166
166
|
|
167
167
|
non_match_response.should eq false
|
168
168
|
end
|
169
169
|
end
|
170
|
-
end
|
170
|
+
end
|
@@ -18,14 +18,14 @@ describe Crowdskout::Services::QuartermasterService do
|
|
18
18
|
|
19
19
|
response = RestClient::Response.create(json, net_http_resp, @request)
|
20
20
|
RestClient.stub(:get).and_return(response)
|
21
|
-
tracking_code = Crowdskout::Services::QuartermasterService.tracking_code
|
21
|
+
tracking_code = Crowdskout::Services::QuartermasterService.new('api_key', 'access_token').tracking_code
|
22
22
|
|
23
23
|
tracking_code.should be_kind_of(Crowdskout::Components::TrackingCode)
|
24
24
|
|
25
25
|
expect(tracking_code.source).to eq 1
|
26
26
|
expect(tracking_code.organization).to eq 2
|
27
27
|
expect(tracking_code.client).to eq 3
|
28
|
-
|
28
|
+
|
29
29
|
expect(tracking_code.tracking_code_source.gsub(/\s+/, " ")).to eq %{
|
30
30
|
<!-- Crowdskout -->
|
31
31
|
<script>
|
@@ -53,4 +53,4 @@ describe Crowdskout::Services::QuartermasterService do
|
|
53
53
|
}.gsub(/\s+/, " ")
|
54
54
|
end
|
55
55
|
end
|
56
|
-
end
|
56
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: crowdskout
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Crowdskout
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2017-
|
13
|
+
date: 2017-10-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rest-client
|
@@ -152,7 +152,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|
154
154
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.4.
|
155
|
+
rubygems_version: 2.4.5.1
|
156
156
|
signing_key:
|
157
157
|
specification_version: 4
|
158
158
|
summary: Crowdskout SDK for Ruby
|