Class: Crowdskout::Services::ProfileService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/crowdskout/services/profile_service.rb

Instance Attribute Summary

Attributes inherited from BaseService

#access_token, #api_key

Instance Method Summary collapse

Methods inherited from BaseService

#initialize

Constructor Details

This class inherits a constructor from Crowdskout::Services::BaseService

Instance Method Details

#check_for_non_match(profile) ⇒ boolean

more info - docs.crowdskout.com/api/#check-for-a-non-match

Check for a non-match. The endpoints returns true if the given Profile object is definitely NOT a match. That means that the ID given in the Profile object does not match the Profile data.

Parameters:

  • profile (Profile)
    • profile to check for non-match

Returns:

  • (boolean)
    • returns true if it is a non-match, false in all other scenarios

Raises:



112
113
114
115
116
117
118
119
120
121
# File 'lib/crowdskout/services/profile_service.rb', line 112

def check_for_non_match(profile)
  raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
  url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.check_for_non_match'), profile.id)
  url = build_url(url)
  payload = {
    profile: profile.to_hash
  }.to_json
  response = RestClient.post(url, payload, get_headers())
  JSON.parse(response.body)["data"]
end

#create_profile(profile) ⇒ Profile

more info - docs.crowdskout.com/api/#create-a-profile Create a new profile

Parameters:

  • profile (Profile)
    • the new profile object to add to Crowdskout

  • params (Hash)
    • A hash with query parameters

Returns:

  • (Profile)
    • the profile object

Raises:



34
35
36
37
38
39
40
41
42
43
# File 'lib/crowdskout/services/profile_service.rb', line 34

def create_profile(profile)
  raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile')
  url = build_url(url)
  payload = {
    profile: profile.to_hash
  }.to_json
  response = RestClient.post(url, payload, get_headers())
  Components::Profile.create(JSON.parse(response.body)["data"])
end

#create_profiles_bulk(profiles) ⇒ ResultSet

more info - docs.crowdskout.com/api/#create-many-profiles Create a bunch of new profiles

Parameters:

  • profiles (Array<Profile>)
    • an array of profile to bulk add

  • params (Hash)
    • A hash with query parameters

Returns:

  • (ResultSet)
    • the results set as an enumeration with profiles

Raises:



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/crowdskout/services/profile_service.rb', line 50

def create_profiles_bulk(profiles)
  raise Exceptions::ServiceException, "Must be an array of profiles." if profiles.nil? || !profiles.is_a?(Array)
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile_bulk')
  url = build_url(url)
  payload = {
    profiles: profiles.collect(&:to_hash)
  }.to_json
  response = RestClient.post(url, payload, get_headers())
  body = JSON.parse(response.body)

  profiles = []
  body['data'].each do |profile|
    profiles << Components::Profile.create(profile)
  end if body['data'].count > 0

  Components::ResultSet.new(profiles, body['messages'])
end

#get_profile(profile_id, collections) ⇒ Profile

more info - docs.crowdskout.com/api/#get-a-profile-by-id Get a profile based on the collections provided

Parameters:

  • profile_id (Integer)
    • the id of the profile

  • collections (String)
    • A csv of the requested collections

Returns:

  • (Profile)
    • the profile object

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/crowdskout/services/profile_service.rb', line 15

def get_profile(profile_id, collections)
  raise Exceptions::ServiceException, "Profile ID is required." if profile_id.nil?
  raise Exceptions::ServiceException, "A comma-deliminted list of collections is required." if collections.nil?
  params = {
    collections: collections
  }
  url = Util::Config.get('endpoints.base_url') +
        sprintf(Util::Config.get('endpoints.crud_profile'), profile_id)
  url = build_url(url, params)

  response = RestClient.get(url, get_headers())
  Components::Profile.create(JSON.parse(response.body)["data"])
end

#update_profile(profile) ⇒ Profile

more info - docs.crowdskout.com/api/#update-a-profile-by-id Update the given profile

Parameters:

  • profile (Profile)
    • the profile to update

Returns:

  • (Profile)
    • the profile object

Raises:



72
73
74
75
76
77
78
79
80
81
# File 'lib/crowdskout/services/profile_service.rb', line 72

def update_profile(profile)
  raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
  url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_profile'), profile.id)
  url = build_url(url)
  payload = {
    profile: profile.to_hash
  }.to_json
  response = RestClient.put(url, payload, get_headers())
  Components::Profile.create(JSON.parse(response.body)["data"])
end

#update_profiles_bulk(profiles) ⇒ ResultSet

more info - docs.crowdskout.com/api/#update-many-profiles Update a bunch of profiles

Parameters:

  • profiles (Array<Profile>)
    • an array of profile to bulk add

Returns:

  • (ResultSet)
    • the results set as an enumeration with profiles

Raises:



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/crowdskout/services/profile_service.rb', line 87

def update_profiles_bulk(profiles)
  raise Exceptions::ServiceException, "Must be an array of profiles." if profiles.nil? || !profiles.is_a?(Array)
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile_bulk')
  url = build_url(url)
  payload = {
    profiles: profiles.collect(&:to_hash)
  }.to_json
  response = RestClient.put(url, payload, get_headers())
  body = JSON.parse(response.body)

  profiles = []
  body['data'].each do |profile|
    profiles << Components::Profile.create(profile)
  end if body['data'].count > 0

  Components::ResultSet.new(profiles, body['messages'])
end