crowdskout 0.0.4 → 0.0.5

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +4 -4
  3. data/crowdskout.gemspec +1 -1
  4. data/lib/crowdskout.rb +4 -2
  5. data/lib/crowdskout/api.rb +8 -2
  6. data/lib/crowdskout/auth/oauth2.rb +6 -0
  7. data/lib/crowdskout/components/attributes/attribute.rb +12 -0
  8. data/lib/crowdskout/components/attributes/option.rb +7 -3
  9. data/lib/crowdskout/components/component.rb +13 -2
  10. data/lib/crowdskout/components/fields/field_options.rb +12 -0
  11. data/lib/crowdskout/components/profiles/collection.rb +30 -0
  12. data/lib/crowdskout/components/profiles/field.rb +29 -0
  13. data/lib/crowdskout/components/profiles/item.rb +34 -0
  14. data/lib/crowdskout/components/profiles/profile.rb +22 -16
  15. data/lib/crowdskout/components/profiles/{name.rb → value.rb} +10 -6
  16. data/lib/crowdskout/components/result_set.rb +4 -2
  17. data/lib/crowdskout/exceptions/oauth2_exception.rb +6 -0
  18. data/lib/crowdskout/exceptions/service_exception.rb +6 -0
  19. data/lib/crowdskout/services/attribute_service.rb +20 -6
  20. data/lib/crowdskout/services/base_service.rb +6 -0
  21. data/lib/crowdskout/services/field_service.rb +11 -0
  22. data/lib/crowdskout/services/profile_service.rb +27 -2
  23. data/lib/crowdskout/util/config.rb +6 -0
  24. data/lib/crowdskout/util/helpers.rb +6 -0
  25. data/lib/crowdskout/version.rb +1 -1
  26. data/spec/crowdskout/auth/oauth2_spec.rb +1 -1
  27. data/spec/crowdskout/services/attribute_service_spec.rb +1 -0
  28. data/spec/crowdskout/services/field_service_spec.rb +1 -0
  29. data/spec/crowdskout/services/profile_service_spec.rb +54 -26
  30. metadata +6 -4
  31. data/lib/crowdskout/components/profiles/gender.rb +0 -40
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 67d2e0750c8be6e9368412b8fd03f60664fa9c9f
4
- data.tar.gz: 8ab86a1381952837ee0a1fd3ab4dd186afb3ee05
3
+ metadata.gz: 26a82fafee392d2d1494dcf24b3eb88689e656fb
4
+ data.tar.gz: 9a6d19a488a1dbe4398ff7e85e0edae5d55c8dc7
5
5
  SHA512:
6
- metadata.gz: 382153bfdb158fe5d8c4fc6d6bfee0f457fdbbc093e505ebc06bd67fc1c44347d7aa34340db802af541cc837e895d167403f177500857bc94a1b0434c237eba2
7
- data.tar.gz: 64842c469da953513a9e23f99e31968594f7f45d572def406380843f09111a2c4fb7c1e423ca300ecc6918280c8f266ce045559f4877aecd279449358c305c33
6
+ metadata.gz: 57cc85584ddcb813b76870d3d681a48634dc7639bd73899c096797aebe83d9fb79aedd54a0a8d5c20128954dc736bd837dca231bed1fc2ce75c569ad29ec23b9
7
+ data.tar.gz: 07e130cf6470641e4bb3f72d332542723f89063e402bacaefdf0acd2c72f51b964e20deb606d41940143fe3da442b4add1c79220991387cac3004cfd76abb337
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # Crowdskout
2
2
 
3
- It is a Ruby wrapper for the Crowdskout API.
3
+ [![Build Status](https://travis-ci.org/revvco/crowdskout.png?branch=master)](https://travis-ci.org/revvco/crowdskout) [![Gem Version](https://badge.fury.io/rb/crowdskout.svg)](https://badge.fury.io/rb/crowdskout) [![Code Climate](https://codeclimate.com/github/revvco/crowdskout/badges/gpa.svg)](https://codeclimate.com/github/revvco/crowdskout)
4
4
 
5
- [![Build Status](https://travis-ci.org/revvco/crowdskout.png?branch=master)](https://travis-ci.org/revvco/crowdskout.png?branch=master)
5
+ A Ruby wrapper for the Crowdskout API.
6
6
 
7
- Visit also a Crowdskout API documentation: [here](http://docs.crowdskout.com/api/#get-the-options-for-a-field)
7
+ Crowdskout API documentation can be found [here](http://docs.crowdskout.com/api/#get-the-options-for-a-field)
8
8
 
9
9
  ## Installation
10
10
 
@@ -50,4 +50,4 @@ Or install it yourself as:
50
50
  field_options = api.get_options_for_a_field("AddressCity")
51
51
 
52
52
  # Fetching attributes
53
- attributes = api.get_attributes
53
+ attributes = api.get_attributes
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.0.4'
8
+ s.version = '0.0.5'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Crowdskout", "Revv","Kyle Schutt"]
11
11
  s.homepage = "https://github.com/revvco/crowdskout"
data/lib/crowdskout.rb CHANGED
@@ -48,8 +48,10 @@ module Crowdskout
48
48
  autoload :Attribute, 'crowdskout/components/attributes/attribute'
49
49
  autoload :Option, 'crowdskout/components/attributes/option'
50
50
  autoload :Profile, 'crowdskout/components/profiles/profile'
51
- autoload :Name, 'crowdskout/components/profiles/name'
52
- autoload :Gender, 'crowdskout/components/profiles/gender'
51
+ autoload :Collection, 'crowdskout/components/profiles/collection'
52
+ autoload :Item, 'crowdskout/components/profiles/item'
53
+ autoload :Field, 'crowdskout/components/profiles/field'
54
+ autoload :Value, 'crowdskout/components/profiles/value'
53
55
  autoload :FieldOptions, 'crowdskout/components/fields/field_options'
54
56
  end
55
57
 
@@ -1,3 +1,9 @@
1
+ #
2
+ # api.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  class Api
3
9
  # Class constructor
@@ -19,7 +25,7 @@ module Crowdskout
19
25
  def get_profile(profile_id, collections)
20
26
  Services::ProfileService.get_profile(profile_id, collections)
21
27
  end
22
- def create_profile(profile, params = {})
28
+ def create_profile(profile)
23
29
  Services::ProfileService.create_profile(profile, params)
24
30
  end
25
31
  def create_profiles_bulk(profiles)
@@ -41,7 +47,7 @@ module Crowdskout
41
47
  def get_attributes(params = {})
42
48
  Services::AttributeService.get_attributes(params)
43
49
  end
44
- def get_attribute(attribute_id)
50
+ def get_attribute(attribute_id, params = {})
45
51
  Services::AttributeService.get_attribute(attribute_id)
46
52
  end
47
53
  def create_attribute(name, type, options = nil)
@@ -1,3 +1,9 @@
1
+ #
2
+ # oauth2.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Auth
3
9
  class OAuth2
@@ -1,8 +1,17 @@
1
+ #
2
+ # attribute.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Components
3
9
  class Attribute < Component
4
10
  attr_accessor :id, :type, :locked, :name, :options
5
11
 
12
+ # Factory method to create an Attribute object from a json string
13
+ # @param [Hash] props - properties to create object from
14
+ # @return [Attribute]
6
15
  def self.create(props)
7
16
  obj = Attribute.new
8
17
  if props
@@ -22,6 +31,9 @@ module Crowdskout
22
31
  obj
23
32
  end
24
33
 
34
+ # Add an Option
35
+ # @param [Option] option
36
+ # @return [Array] the options array
25
37
  def add_options(option)
26
38
  @options = [] if @options.nil?
27
39
  @options << option
@@ -1,13 +1,17 @@
1
- # Copyright (c) 2016 Kyle Schutt. All rights reserved.require
1
+ #
2
+ # option.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
2
6
 
3
7
  module Crowdskout
4
8
  module Components
5
9
  class Option < Component
6
10
  attr_accessor :id, :value
7
11
 
8
- # Factory method to create an Address object from a json string
12
+ # Factory method to create an Option object from a json string
9
13
  # @param [Hash] props - properties to create object from
10
- # @return [Address]
14
+ # @return [Option]
11
15
  def self.create(props)
12
16
  obj = Option.new
13
17
  if props
@@ -1,7 +1,15 @@
1
+ #
2
+ # component.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Components
3
9
  class Component
4
10
 
11
+ # Return the object as hash
12
+ # @return [Hash]
5
13
  def to_hash
6
14
  hash = Hash.new
7
15
  self.instance_variables.collect do |var|
@@ -10,6 +18,9 @@ module Crowdskout
10
18
  hash
11
19
  end
12
20
 
21
+ # Get the nested value as a hash
22
+ # @param [Object] an object to change into a hash
23
+ # @return [Hash] hash of the val
13
24
  def self.to_hash_value(val)
14
25
  if val.is_a? Crowdskout::Components::Component
15
26
  return val.to_hash
@@ -22,12 +33,12 @@ module Crowdskout
22
33
  end
23
34
  end
24
35
 
36
+ # Object to a json string
37
+ # @return [String] the hash of the object to a json string
25
38
  def to_json(val = nil)
26
39
  self.to_hash.to_json
27
40
  end
28
41
 
29
- protected
30
-
31
42
  # Get the requested value from a hash, or return the default
32
43
  # @param [Hash] hsh - the hash to search for the provided hash key
33
44
  # @param [String] key - hash key to look for
@@ -1,8 +1,17 @@
1
+ #
2
+ # field_options.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Components
3
9
  class FieldOptions < Component
4
10
  attr_accessor :id, :collection, :options
5
11
 
12
+ # Factory method to create an FieldOptions object from a json string
13
+ # @param [Hash] props - properties to create object from
14
+ # @return [FieldOptions]
6
15
  def self.create(props)
7
16
  obj = FieldOptions.new
8
17
  if props
@@ -22,6 +31,9 @@ module Crowdskout
22
31
  obj
23
32
  end
24
33
 
34
+ # Add an Option
35
+ # @param [Option] option
36
+ # @return [Array] the options array
25
37
  def add_options(option)
26
38
  @options = [] if @options.nil?
27
39
  @options << option
@@ -0,0 +1,30 @@
1
+ #
2
+ # collection.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
7
+ module Crowdskout
8
+ module Components
9
+ class Collection < Component
10
+ attr_accessor :key_name, :items
11
+
12
+ # Factory method to create an Collection object from a json string
13
+ # @param [String] key_name - name of the collection
14
+ # @param [Array] items - properties to create object from
15
+ # @return [Collection]
16
+ def self.create(key_name, items)
17
+ obj = Collection.new
18
+ obj.key_name = key_name
19
+ obj.items = []
20
+ if items
21
+ items.each do |item|
22
+ # item is a hash of fields
23
+ obj.items << Components::Item.create(item)
24
+ end
25
+ end
26
+ obj
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,29 @@
1
+ #
2
+ # field.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
7
+ module Crowdskout
8
+ module Components
9
+ class Field < Component
10
+ # value can either be a string or a hash
11
+ attr_accessor :key_name, :value
12
+
13
+ # Factory method to create an Field object from a json string
14
+ # @param [String] key_name - name of the Field
15
+ # @param [Hash or String] value - properties to create object from
16
+ # @return [Field]
17
+ def self.create(key_name, value)
18
+ obj = Field.new
19
+ obj.key_name = key_name
20
+ if value.is_a?(Hash)
21
+ obj.value = Value.create(value)
22
+ else
23
+ obj.value = value.to_s
24
+ end
25
+ obj
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,34 @@
1
+ #
2
+ # item.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
7
+ module Crowdskout
8
+ module Components
9
+ class Item < Component
10
+ attr_accessor :id, :fields, :delete
11
+
12
+ # Factory method to create an Item object from a json string
13
+ # @param [Hash] props - properties to create object from
14
+ # @return [Item]
15
+ def self.create(props)
16
+ obj = Item.new
17
+ obj.id = 0
18
+ obj.fields = []
19
+ if props
20
+ props.each do |key, value|
21
+ if ['id'].include? key.downcase
22
+ obj.send("#{key}=", value) if obj.respond_to? key
23
+ else
24
+ # key is the name of the field
25
+ # value is the field's value
26
+ obj.fields << Components::Field.create(key, value)
27
+ end
28
+ end
29
+ end
30
+ obj
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,39 +1,45 @@
1
+ #
2
+ # profile.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Components
3
9
  class Profile < Component
4
- attr_accessor :id, :names, :genders
10
+ attr_accessor :id, :collections
5
11
 
12
+ # Factory method to create an Profile object from a json string
13
+ # @param [Hash] props - properties to create object from
14
+ # @return [Profile]
6
15
  def self.create(props)
7
16
  obj = Profile.new
17
+ obj.collections = []
8
18
  if props
9
19
  props.each do |key, value|
10
- if key.downcase == 'names'
11
- if value
12
- obj.names = []
13
- value.each do |name|
14
- obj.names << Components::Name.create(name)
15
- end
16
- end
17
- elsif key.downcase == 'genders'
18
- if value
19
- obj.genders = []
20
- value.each do |gender|
21
- obj.genders << Components::Gender.create(gender)
22
- end
23
- end
24
- else
20
+ if ['id'].include? key.downcase
25
21
  obj.send("#{key}=", value) if obj.respond_to? key
22
+ else
23
+ # the key is the name of the collection
24
+ # the value is an array of items
25
+ obj.collections << Components::Collection.create(key, value)
26
26
  end
27
27
  end
28
28
  end
29
29
  obj
30
30
  end
31
31
 
32
+ # Add a Name
33
+ # @param [Name] name
34
+ # @return [Array] the names array
32
35
  def add_names(name)
33
36
  @names = [] if @names.nil?
34
37
  @names << name
35
38
  end
36
39
 
40
+ # Add a Gender
41
+ # @param [Gebder] gender
42
+ # @return [Array] the genders array
37
43
  def add_genders(gender)
38
44
  @genders = [] if @genders.nil?
39
45
  @genders << gender
@@ -1,15 +1,19 @@
1
- # Copyright (c) 2016 Kyle Schutt. All rights reserved.require
1
+ #
2
+ # value.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
2
6
 
3
7
  module Crowdskout
4
8
  module Components
5
- class Name < Component
6
- attr_accessor :id, :FullName, :NameTitle, :FirstName, :MiddleName, :LastName, :NameSuffix
9
+ class Value < Component
10
+ attr_accessor :id, :value
7
11
 
8
- # Factory method to create an Address object from a json string
12
+ # Factory method to create an Value object from a json string
9
13
  # @param [Hash] props - properties to create object from
10
- # @return [Address]
14
+ # @return [Value]
11
15
  def self.create(props)
12
- obj = Name.new
16
+ obj = Value.new
13
17
  if props
14
18
  props.each do |key, value|
15
19
  obj.send("#{key}=", value) if obj.respond_to? key
@@ -1,14 +1,16 @@
1
1
  #
2
2
  # result_set.rb
3
+ # Crowdskout
3
4
  #
4
5
  # Copyright (c) 2016 Kyle Schutt. All rights reserved.
5
6
 
6
7
  module Crowdskout
7
8
  module Components
8
9
  class ResultSet
9
- attr_accessor :results, :next
10
- def initialize(results, meta)
10
+ attr_accessor :results, :messages
11
+ def initialize(results, messages)
11
12
  @results = results
13
+ @messages = messages
12
14
  end
13
15
  end
14
16
  end
@@ -1,3 +1,9 @@
1
+ #
2
+ # oauth2_exception.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Exceptions
3
9
  class OAuth2Exception < Exception; end
@@ -1,3 +1,9 @@
1
+ #
2
+ # service_exception.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Exceptions
3
9
  class ServiceException < Exception; end
@@ -1,12 +1,17 @@
1
+ #
2
+ # attribute_service.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Services
3
9
  class AttributeService < BaseService
4
10
  class << self
5
11
 
6
12
  # More info - http://docs.crowdskout.com/api/#get-all-attributes
7
- # @param params - query parameters
8
- # - limit - the number of attributes to limit
9
- # - offset - the number of attributes to skip
13
+ # @param [Hash] params - query parameters
14
+ # @return [ResultSet] set of Components::Attributes
10
15
  def get_attributes(params = {})
11
16
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.attributes')
12
17
  url = build_url(url, params)
@@ -23,17 +28,21 @@ module Crowdskout
23
28
  end
24
29
 
25
30
  # more info - http://docs.crowdskout.com/api/#get-an-attribute-by-id
26
- # @param [Integration] attribute_id - the id of the attribute to fetch
27
- def get_attribute(attribute_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 = {})
28
35
  raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil?
29
36
  url = Util::Config.get('endpoints.base_url') +
30
37
  sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id)
31
- url = build_url(url)
38
+ url = build_url(url, params)
32
39
  response = RestClient.get(url, get_headers())
33
40
  Components::Attribute.create(JSON.parse(response.body)["data"])
34
41
  end
35
42
 
36
43
  # more info - http://docs.crowdskout.com/api/#create-an-attribute
44
+ # @param [Attribute] attribute - attribute object to add to Crowdskout
45
+ # @return [Attribute]
37
46
  def create_attribute(new_attribute)
38
47
  raise Exceptions::ServiceException, "Attribute must not be nil" if new_attribute.nil?
39
48
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.attribute')
@@ -44,6 +53,9 @@ module Crowdskout
44
53
  end
45
54
 
46
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]
47
59
  def update_attribute(attribute_id, params = {})
48
60
  raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil?
49
61
  url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id)
@@ -53,6 +65,8 @@ module Crowdskout
53
65
  end
54
66
 
55
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]
56
70
  def delete_attribute(attribute_id)
57
71
  raise Exceptions::ServiceException, "Attribute ID is required." if attribute_id.nil?
58
72
  url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_attribute'), attribute_id)
@@ -1,3 +1,9 @@
1
+ #
2
+ # attribute_service.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Services
3
9
  class BaseService
@@ -1,8 +1,19 @@
1
+ #
2
+ # field_service.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Services
3
9
  class FieldService < BaseService
4
10
  class << self
11
+
5
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
6
17
  def get_options_for_a_field(field_name, params = {})
7
18
  raise Exceptions::ServiceException, "Field name is required." if field_name.nil?
8
19
  url = Util::Config.get('endpoints.base_url') +
@@ -1,8 +1,19 @@
1
+ #
2
+ # profile_service.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Services
3
9
  class ProfileService < BaseService
4
10
  class << self
11
+
5
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
6
17
  def get_profile(profile_id, collections)
7
18
  raise Exceptions::ServiceException, "Profile ID is required." if profile_id.nil?
8
19
  raise Exceptions::ServiceException, "A comma-deliminted list of collections is required." if collections.nil?
@@ -18,16 +29,24 @@ module Crowdskout
18
29
  end
19
30
 
20
31
  # more info - http://docs.crowdskout.com/api/#create-a-profile
21
- def create_profile(profile, params = {})
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)
22
37
  raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
23
38
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile')
24
- url = build_url(url, params)
39
+ url = build_url(url)
25
40
  payload = profile.to_json
26
41
  response = RestClient.post(url, payload, get_headers())
27
42
  Components::Profile.create(JSON.parse(response.body)["data"])
28
43
  end
29
44
 
30
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
31
50
  def create_profiles_bulk(profiles)
32
51
  raise Exceptions::ServiceException, "Must be an array of profiles." if profiles.nil? || !profiles.is_a?(Array)
33
52
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile_bulk')
@@ -45,6 +64,9 @@ module Crowdskout
45
64
  end
46
65
 
47
66
  # more info - http://docs.crowdskout.com/api/#update-a-profile-by-id
67
+ # Update the given profile
68
+ # @param [Profile] profile - the profile to update
69
+ # @return [Profile] - the profile object
48
70
  def update_profile(profile)
49
71
  raise Exceptions::ServiceException, "Profile object must not be nil." if profile.nil?
50
72
  url = Util::Config.get('endpoints.base_url') + sprintf(Util::Config.get('endpoints.crud_profile'), profile.id)
@@ -55,6 +77,9 @@ module Crowdskout
55
77
  end
56
78
 
57
79
  # more info - http://docs.crowdskout.com/api/#update-many-profiles
80
+ # Update a bunch of profiles
81
+ # @param [Array<Profile>] profiles - an array of profile to bulk add
82
+ # @return [ResultSet] - the results set as an enumeration with profiles
58
83
  def update_profiles_bulk(profiles)
59
84
  raise Exceptions::ServiceException, "Must be an array of profiles." if profiles.nil? || !profiles.is_a?(Array)
60
85
  url = Util::Config.get('endpoints.base_url') + Util::Config.get('endpoints.profile_bulk')
@@ -1,3 +1,9 @@
1
+ #
2
+ # config.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Util
3
9
  class Config
@@ -1,3 +1,9 @@
1
+ #
2
+ # helpers.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.
6
+
1
7
  module Crowdskout
2
8
  module Util
3
9
  class Helpers
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Crowdskout
22
- VERSION = '0.0.4'
22
+ VERSION = '0.0.5'
23
23
  end
@@ -1,4 +1,4 @@
1
- #
1
+ #
2
2
  # oauth2_spec.rb
3
3
  # Crowdskout
4
4
  #
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # attribute_service_spec.rb
3
+ # Crowdskout
3
4
  #
4
5
  # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
5
6
 
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # field_service_spec.rb
3
+ # Crowdskout
3
4
  #
4
5
  # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
5
6
 
@@ -1,5 +1,6 @@
1
1
  #
2
2
  # profile_service_spec.rb
3
+ # Crowdskout
3
4
  #
4
5
  # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
5
6
 
@@ -20,11 +21,17 @@ describe Crowdskout::Services::ProfileService do
20
21
  profile = Crowdskout::Services::ProfileService.get_profile(1, "Names,Genders")
21
22
 
22
23
  profile.should be_kind_of(Crowdskout::Components::Profile)
23
- profile.names[0].should be_kind_of(Crowdskout::Components::Name)
24
- profile.names[0].FullName.should eq 'Mr. Ferdinand Magellan'
25
- profile.genders[0].should be_kind_of(Crowdskout::Components::Gender)
26
- profile.genders[0].gender.should be_kind_of(Crowdskout::Components::GenderInfo)
27
- profile.genders[0].gender.value.should eq 'Male'
24
+ profile.collections[1].should be_kind_of(Crowdskout::Components::Collection)
25
+ profile.collections[1].key_name.should eq 'Genders'
26
+ profile.collections[1].items[0].should be_kind_of(Crowdskout::Components::Item)
27
+ profile.collections[1].items[0].id.should eq 1
28
+ profile.collections[1].items[0].fields[0].should be_kind_of(Crowdskout::Components::Field)
29
+ profile.collections[1].items[0].fields[0].key_name.should eq "Gender"
30
+ profile.collections[1].items[0].fields[0].value.should be_kind_of(Crowdskout::Components::Value)
31
+ profile.collections[1].items[0].fields[0].value.id.should eq 1
32
+ profile.collections[1].items[0].fields[0].value.value.should eq "Male"
33
+ profile.collections[1].items[0].fields[1].key_name.should eq "TestValue"
34
+ profile.collections[1].items[0].fields[1].value.should eq "value"
28
35
  end
29
36
  end
30
37
 
@@ -35,15 +42,21 @@ describe Crowdskout::Services::ProfileService do
35
42
 
36
43
  response = RestClient::Response.create(json, net_http_resp, {}, @request)
37
44
  RestClient.stub(:post).and_return(response)
38
- new_profile = Crowdskout::Components::Profile.create(JSON.parse(json))
45
+ new_profile = Crowdskout::Components::Profile.create(JSON.parse(json)["data"])
39
46
  profile = Crowdskout::Services::ProfileService.create_profile(new_profile)
40
47
 
41
48
  profile.should be_kind_of(Crowdskout::Components::Profile)
42
- profile.names[0].should be_kind_of(Crowdskout::Components::Name)
43
- profile.names[0].FullName.should eq 'Mr. Ferdinand Magellan'
44
- profile.genders[0].should be_kind_of(Crowdskout::Components::Gender)
45
- profile.genders[0].gender.should be_kind_of(Crowdskout::Components::GenderInfo)
46
- profile.genders[0].gender.value.should eq 'Male'
49
+ profile.collections[1].should be_kind_of(Crowdskout::Components::Collection)
50
+ profile.collections[1].key_name.should eq 'Genders'
51
+ profile.collections[1].items[0].should be_kind_of(Crowdskout::Components::Item)
52
+ profile.collections[1].items[0].id.should eq 1
53
+ profile.collections[1].items[0].fields[0].should be_kind_of(Crowdskout::Components::Field)
54
+ profile.collections[1].items[0].fields[0].key_name.should eq "Gender"
55
+ profile.collections[1].items[0].fields[0].value.should be_kind_of(Crowdskout::Components::Value)
56
+ profile.collections[1].items[0].fields[0].value.id.should eq 1
57
+ profile.collections[1].items[0].fields[0].value.value.should eq "Male"
58
+ profile.collections[1].items[0].fields[1].key_name.should eq "TestValue"
59
+ profile.collections[1].items[0].fields[1].value.should eq "value"
47
60
  end
48
61
  end
49
62
 
@@ -54,7 +67,6 @@ describe Crowdskout::Services::ProfileService do
54
67
 
55
68
  response = RestClient::Response.create(json, net_http_resp, {}, @request)
56
69
  RestClient.stub(:post).and_return(response)
57
- new_profile = Crowdskout::Components::Profile.create(JSON.parse(json))
58
70
  profiles = []
59
71
  body = JSON.parse(json)
60
72
  body['data'].each do |profile|
@@ -65,9 +77,15 @@ describe Crowdskout::Services::ProfileService do
65
77
 
66
78
  profiles.should be_kind_of(Crowdskout::Components::ResultSet)
67
79
  profile.should be_kind_of(Crowdskout::Components::Profile)
68
- profile.genders[0].should be_kind_of(Crowdskout::Components::Gender)
69
- profile.genders[0].gender.should be_kind_of(Crowdskout::Components::GenderInfo)
70
- profile.genders[0].gender.value.should eq 'Male'
80
+ profile.collections[0].should be_kind_of(Crowdskout::Components::Collection)
81
+ profile.collections[0].key_name.should eq 'Genders'
82
+ profile.collections[0].items[0].should be_kind_of(Crowdskout::Components::Item)
83
+ profile.collections[0].items[0].id.should eq 1
84
+ profile.collections[0].items[0].fields[0].should be_kind_of(Crowdskout::Components::Field)
85
+ profile.collections[0].items[0].fields[0].key_name.should eq "Gender"
86
+ profile.collections[0].items[0].fields[0].value.should be_kind_of(Crowdskout::Components::Value)
87
+ profile.collections[0].items[0].fields[0].value.id.should eq 1
88
+ profile.collections[0].items[0].fields[0].value.value.should eq "Male"
71
89
  end
72
90
  end
73
91
 
@@ -78,15 +96,21 @@ describe Crowdskout::Services::ProfileService do
78
96
 
79
97
  response = RestClient::Response.create(json, net_http_resp, {}, @request)
80
98
  RestClient.stub(:put).and_return(response)
81
- profile = Crowdskout::Components::Profile.create(JSON.parse(json))
99
+ profile = Crowdskout::Components::Profile.create(JSON.parse(json)["data"])
82
100
  result = Crowdskout::Services::ProfileService.update_profile(profile)
83
101
 
84
102
  result.should be_kind_of(Crowdskout::Components::Profile)
85
- result.names[0].should be_kind_of(Crowdskout::Components::Name)
86
- result.names[0].FullName.should eq 'Mr. Ferdinand Magellan'
87
- result.genders[0].should be_kind_of(Crowdskout::Components::Gender)
88
- result.genders[0].gender.should be_kind_of(Crowdskout::Components::GenderInfo)
89
- result.genders[0].gender.value.should eq 'Male'
103
+ result.collections[1].should be_kind_of(Crowdskout::Components::Collection)
104
+ result.collections[1].key_name.should eq 'Genders'
105
+ result.collections[1].items[0].should be_kind_of(Crowdskout::Components::Item)
106
+ result.collections[1].items[0].id.should eq 1
107
+ result.collections[1].items[0].fields[0].should be_kind_of(Crowdskout::Components::Field)
108
+ result.collections[1].items[0].fields[0].key_name.should eq "Gender"
109
+ result.collections[1].items[0].fields[0].value.should be_kind_of(Crowdskout::Components::Value)
110
+ result.collections[1].items[0].fields[0].value.id.should eq 1
111
+ result.collections[1].items[0].fields[0].value.value.should eq "Male"
112
+ result.collections[1].items[0].fields[1].key_name.should eq "TestValue"
113
+ result.collections[1].items[0].fields[1].value.should eq "value"
90
114
  end
91
115
  end
92
116
 
@@ -97,7 +121,6 @@ describe Crowdskout::Services::ProfileService do
97
121
 
98
122
  response = RestClient::Response.create(json, net_http_resp, {}, @request)
99
123
  RestClient.stub(:put).and_return(response)
100
- new_profile = Crowdskout::Components::Profile.create(JSON.parse(json))
101
124
  profiles = []
102
125
  body = JSON.parse(json)
103
126
  body['data'].each do |profile|
@@ -107,10 +130,15 @@ describe Crowdskout::Services::ProfileService do
107
130
  profile = profiles.results[0]
108
131
 
109
132
  profiles.should be_kind_of(Crowdskout::Components::ResultSet)
110
- profile.should be_kind_of(Crowdskout::Components::Profile)
111
- profile.genders[0].should be_kind_of(Crowdskout::Components::Gender)
112
- profile.genders[0].gender.should be_kind_of(Crowdskout::Components::GenderInfo)
113
- profile.genders[0].gender.value.should eq 'Male'
133
+ profile.collections[0].should be_kind_of(Crowdskout::Components::Collection)
134
+ profile.collections[0].key_name.should eq 'Genders'
135
+ profile.collections[0].items[0].should be_kind_of(Crowdskout::Components::Item)
136
+ profile.collections[0].items[0].id.should eq 1
137
+ profile.collections[0].items[0].fields[0].should be_kind_of(Crowdskout::Components::Field)
138
+ profile.collections[0].items[0].fields[0].key_name.should eq "Gender"
139
+ profile.collections[0].items[0].fields[0].value.should be_kind_of(Crowdskout::Components::Value)
140
+ profile.collections[0].items[0].fields[0].value.id.should eq 1
141
+ profile.collections[0].items[0].fields[0].value.value.should eq "Male"
114
142
  end
115
143
  end
116
144
  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.0.4
4
+ version: 0.0.5
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: 2016-05-03 00:00:00.000000000 Z
13
+ date: 2016-05-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -102,9 +102,11 @@ files:
102
102
  - lib/crowdskout/components/attributes/option.rb
103
103
  - lib/crowdskout/components/component.rb
104
104
  - lib/crowdskout/components/fields/field_options.rb
105
- - lib/crowdskout/components/profiles/gender.rb
106
- - lib/crowdskout/components/profiles/name.rb
105
+ - lib/crowdskout/components/profiles/collection.rb
106
+ - lib/crowdskout/components/profiles/field.rb
107
+ - lib/crowdskout/components/profiles/item.rb
107
108
  - lib/crowdskout/components/profiles/profile.rb
109
+ - lib/crowdskout/components/profiles/value.rb
108
110
  - lib/crowdskout/components/result_set.rb
109
111
  - lib/crowdskout/exceptions/oauth2_exception.rb
110
112
  - lib/crowdskout/exceptions/service_exception.rb
@@ -1,40 +0,0 @@
1
- # Copyright (c) 2016 Kyle Schutt. All rights reserved.require
2
-
3
- module Crowdskout
4
- module Components
5
- class Gender < Component
6
- attr_accessor :id, :gender
7
-
8
- # Factory method to create an Address object from a json string
9
- # @param [Hash] props - properties to create object from
10
- # @return [Address]
11
- def self.create(props)
12
- obj = Gender.new
13
- if props
14
- props.each do |key, value|
15
- if key.downcase == 'gender'
16
- obj.gender = GenderInfo.create(value)
17
- else
18
- obj.send("#{key}=", value) if obj.respond_to? key
19
- end
20
- end
21
- end
22
- obj
23
- end
24
- end
25
-
26
- # Detailed gender information
27
- class GenderInfo
28
- attr_accessor :id, :value
29
- def self.create(props)
30
- obj = GenderInfo.new
31
- if props
32
- props.each do |key, value|
33
- obj.send("#{key}=", value) if obj.respond_to? key
34
- end
35
- end
36
- obj
37
- end
38
- end
39
- end
40
- end