crowdskout 0.1.2 → 0.1.3

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: 9c11e380a90d3eed4822ce3fd700ca4b7731bd34
4
- data.tar.gz: bd92f540abcdaddf24694a9858a83f70997af221
3
+ metadata.gz: 33c5a1c083c3e9f945343fcdff2642adbeeef50f
4
+ data.tar.gz: e8b36820423e9fff116715c91de4ccab284b85c0
5
5
  SHA512:
6
- metadata.gz: e73e26b0550180cc3f53aed283b602b3b4f671c071bbfacbecd96f3d1eca6335cf5c7ba76300ad501dc172626805afe6cedf4f83393e6696c9e9e5cfed0cd50e
7
- data.tar.gz: 732de1f2827176b0328c65539c7f54f2d84ee0fc5d65703e62409da3a9879b041c093c92da343b1f5782afd03bf8e00fbd494ded9d56458d289ede9e25aa5434
6
+ metadata.gz: cb066cd2ad5f866565544a17ce96beff1e7e059261a812876875dad1aa78d75dca7be8e1c1297686988744023f1fae3584621efa2869db9b5998eaf4af391475
7
+ data.tar.gz: cf490e66c32d7f02fdf35fb80dafc92c7613166327f5cf6d8d5232e605743ddc878a3a65dbdac035013531bd3d75937ddc17e427395deffa4cfbb2707fb9c77e
@@ -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.2'
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
@@ -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
- Services::BaseService.api_key = api_key || Util::Config.get('auth.api_key')
15
- Services::BaseService.access_token = access_token
16
- if Services::BaseService.api_key.nil? || Services::BaseService.api_key == ''
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 Services::BaseService.access_token.nil? || Services::BaseService.access_token == ''
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
- # More info - http://docs.crowdskout.com/api/#get-all-attributes
13
- # @param [Hash] params - query parameters
14
- # @return [ResultSet] set of Components::Attributes
15
- def get_attributes(params = {})
16
- url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.attributes')
17
- url = build_url(url, params)
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
- response = RestClient.get(url, get_headers())
20
- body = JSON.parse(response.body)
18
+ response = RestClient.get(url, get_headers())
19
+ body = JSON.parse(response.body)
21
20
 
22
- attributes = []
23
- body['data']['list'].each do |attribute|
24
- attributes << Components::Attribute.create(attribute)
25
- end if body['data']["total"] > 0
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
- Components::ResultSet.new(attributes, body['messages'])
28
- end
26
+ Components::ResultSet.new(attributes, body['messages'])
27
+ end
29
28
 
30
- # more info - http://docs.crowdskout.com/api/#get-an-attribute-by-id
31
- # @param [Integer] attribute_id - the id of the attribute to fetch
32
- # @param [Hash] params - query parameters
33
- # @return [Attribute]
34
- def get_attribute(attribute_id, params = {})
35
- raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil?
36
- url = Util::Config.get('endpoints.base_url') +
37
- sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id)
38
- url = build_url(url, params)
39
- response = RestClient.get(url, get_headers())
40
- Components::Attribute.create(JSON.parse(response.body)["data"])
41
- end
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
- # more info - http://docs.crowdskout.com/api/#create-an-attribute
44
- # @param [Attribute] attribute - attribute object to add to Crowdskout
45
- # @return [Attribute]
46
- def create_attribute(new_attribute)
47
- raise Exceptions::ServiceException, "Attribute must not be nil" if new_attribute.nil?
48
- url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.attribute')
49
- url = build_url(url)
50
- payload = new_attribute.to_json
51
- response = RestClient.post(url, payload, get_headers())
52
- Components::Attribute.create(JSON.parse(response.body)["data"])
53
- end
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
- # more info - http://docs.crowdskout.com/api/#update-an-attribute
56
- # @param [Integer] attribute_id - the id of the attribute to update
57
- # @param [Hash] params - query parameters
58
- # @return [Attribute]
59
- def update_attribute(attribute_id, params = {})
60
- raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil?
61
- url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id)
62
- url = build_url(url)
63
- response = RestClient.put(url, params, get_headers())
64
- Components::Attribute.create(JSON.parse(response.body)["data"])
65
- end
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
- # more info - http://docs.crowdskout.com/api/#delete-an-attribute
68
- # @param [Integer] attribute_id - the id of the attribute to update
69
- # @return [boolean]
70
- def delete_attribute(attribute_id)
71
- raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil?
72
- url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id)
73
- url = build_url(url)
74
- response = RestClient.delete(url, get_headers())
75
- response.code == 204
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
- class << self
11
- attr_accessor :api_key, :access_token
10
+ attr_accessor :api_key, :access_token
12
11
 
13
- protected
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
- # Return required headers for making an http request with Crowdskout
16
- # @param [String] content_type - The MIME type of the body of the request, default is 'application/json'
17
- # @return [Hash] - authorization headers
18
- def get_headers(content_type = 'application/json')
19
- {
20
- :content_type => content_type,
21
- :accept => 'application/json',
22
- :authorization => "Bearer #{BaseService.access_token}",
23
- :user_agent => "AppConnect Ruby SDK v#{Crowdskout::VERSION} (#{RUBY_DESCRIPTION})",
24
- :x_ctct_request_source => "sdk.ruby.#{Crowdskout::VERSION}"
25
- }
26
- end
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
- # Build a url from the base url and query parameters hash. Query parameters
29
- # should not be URL encoded because this method will handle that
30
- # @param [String] url - The base url
31
- # @param [Hash] params - A hash with query parameters
32
- # @return [String] - the url with query parameters hash
33
- def build_url(url, params = nil)
34
- if params.respond_to? :each
35
- params.each do |key, value|
36
- # Convert dates to CC date format
37
- if value.respond_to? :iso8601
38
- params[key] = value.iso8601
39
- end
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
- if key.to_s == 'next' && value.match(/^.*?next=(.*)$/)
42
- params[key] = $1
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['api_key'] = BaseService.api_key
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
- class << self
11
-
12
- # more info - http://docs.crowdskout.com/api/#get-the-options-for-a-field
13
- # Get the options for a field
14
- # @param [String] field_name - the name of the field
15
- # @param [Hash] params - A hash with query parameters
16
- # @return [FieldOptions] - the field options
17
- def get_options_for_a_field(field_name, params = {})
18
- raise Exceptions::ServiceException, "Field name is required." if field_name.nil?
19
- url = Util::Config.get('endpoints.base_url') +
20
- sprintf(Util::Config.get('endpoints.fields_options'), field_name)
21
- url = build_url(url, params)
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
- class << self
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
- # more info - http://docs.crowdskout.com/api/#get-a-profile-by-id
13
- # Get a profile based on the collections provided
14
- # @param [Integer] profile_id - the id of the profile
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
- # more info - http://docs.crowdskout.com/api/#create-a-profile
32
- # Create a new profile
33
- # @param [Profile] profile - the new profile object to add to Crowdskout
34
- # @param [Hash] params - A hash with query parameters
35
- # @return [Profile] - the profile object
36
- def create_profile(profile)
37
- raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
38
- url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile')
39
- url = build_url(url)
40
- payload = {
41
- profile: profile.to_hash
42
- }.to_json
43
- response = RestClient.post(url, payload, get_headers())
44
- Components::Profile.create(JSON.parse(response.body)["data"])
45
- end
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
- # more info - http://docs.crowdskout.com/api/#create-many-profiles
48
- # Create a bunch of new profiles
49
- # @param [Array<Profile>] profiles - an array of profile to bulk add
50
- # @param [Hash] params - A hash with query parameters
51
- # @return [ResultSet] - the results set as an enumeration with profiles
52
- def create_profiles_bulk(profiles)
53
- raise Exceptions::ServiceException, "Must be an array of profiles." if profiles.nil? || !profiles.is_a?(Array)
54
- url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile_bulk')
55
- url = build_url(url)
56
- payload = {
57
- profiles: profiles.collect(&:to_hash)
58
- }.to_json
59
- response = RestClient.post(url, payload, get_headers())
60
- body = JSON.parse(response.body)
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
- profiles = []
63
- body['data'].each do |profile|
64
- profiles << Components::Profile.create(profile)
65
- end if body['data'].count > 0
60
+ profiles = []
61
+ body['data'].each do |profile|
62
+ profiles << Components::Profile.create(profile)
63
+ end if body['data'].count > 0
66
64
 
67
- Components::ResultSet.new(profiles, body['messages'])
68
- end
65
+ Components::ResultSet.new(profiles, body['messages'])
66
+ end
69
67
 
70
- # more info - http://docs.crowdskout.com/api/#update-a-profile-by-id
71
- # Update the given profile
72
- # @param [Profile] profile - the profile to update
73
- # @return [Profile] - the profile object
74
- def update_profile(profile)
75
- raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
76
- url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_profile'), profile.id)
77
- url = build_url(url)
78
- payload = {
79
- profile: profile.to_hash
80
- }.to_json
81
- response = RestClient.put(url, payload, get_headers())
82
- Components::Profile.create(JSON.parse(response.body)["data"])
83
- end
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
- # more info - http://docs.crowdskout.com/api/#update-many-profiles
86
- # Update a bunch of profiles
87
- # @param [Array<Profile>] profiles - an array of profile to bulk add
88
- # @return [ResultSet] - the results set as an enumeration with profiles
89
- def update_profiles_bulk(profiles)
90
- raise Exceptions::ServiceException, "Must be an array of profiles." if profiles.nil? || !profiles.is_a?(Array)
91
- url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile_bulk')
92
- url = build_url(url)
93
- payload = {
94
- profiles: profiles.collect(&:to_hash)
95
- }.to_json
96
- response = RestClient.put(url, payload, get_headers())
97
- body = JSON.parse(response.body)
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
- profiles = []
100
- body['data'].each do |profile|
101
- profiles << Components::Profile.create(profile)
102
- end if body['data'].count > 0
97
+ profiles = []
98
+ body['data'].each do |profile|
99
+ profiles << Components::Profile.create(profile)
100
+ end if body['data'].count > 0
103
101
 
104
- Components::ResultSet.new(profiles, body['messages'])
105
- end
102
+ Components::ResultSet.new(profiles, body['messages'])
103
+ end
106
104
 
107
- # more info - https://docs.crowdskout.com/api/#check-for-a-non-match
108
- #
109
- # Check for a non-match. The endpoints returns true if the given Profile object is definitely NOT a match.
110
- # That means that the ID given in the Profile object does not match the Profile data.
111
- #
112
- # @param [Profile] profile - profile to check for non-match
113
- # @return [boolean] - returns true if it is a non-match, false in all other scenarios
114
- def check_for_non_match(profile)
115
- raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
116
- url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.check_for_non_match'), profile.id)
117
- url = build_url(url)
118
- payload = {
119
- profile: profile.to_hash
120
- }.to_json
121
- response = RestClient.post(url, payload, get_headers())
122
- JSON.parse(response.body)["data"]
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
- class << self
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
- # More info - to get the tracking codes for CrowdSkout
13
- # @return [Components::TrackingCode] Components::TrackingCode
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
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Crowdskout
22
- VERSION = '0.1.2'
22
+ VERSION = '0.1.3'.freeze
23
23
  end
@@ -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.2
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-05-18 00:00:00.000000000 Z
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.8
155
+ rubygems_version: 2.4.5.1
156
156
  signing_key:
157
157
  specification_version: 4
158
158
  summary: Crowdskout SDK for Ruby