crowdskout 0.0.5 → 0.0.6

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26a82fafee392d2d1494dcf24b3eb88689e656fb
4
- data.tar.gz: 9a6d19a488a1dbe4398ff7e85e0edae5d55c8dc7
3
+ metadata.gz: 23a7dcaaa6dc1c5c7a3f36f2926b986e869bef96
4
+ data.tar.gz: dd8a9c09d0e8834837f65fa03e787d9bf0325d25
5
5
  SHA512:
6
- metadata.gz: 57cc85584ddcb813b76870d3d681a48634dc7639bd73899c096797aebe83d9fb79aedd54a0a8d5c20128954dc736bd837dca231bed1fc2ce75c569ad29ec23b9
7
- data.tar.gz: 07e130cf6470641e4bb3f72d332542723f89063e402bacaefdf0acd2c72f51b964e20deb606d41940143fe3da442b4add1c79220991387cac3004cfd76abb337
6
+ metadata.gz: 381d154794cadddc34323a8db6f38caeecf65b46a103b6f22188a3bf738424102ccf3c90084fa053275747bb015d58a587769edea1e70679354a36676f74b96c
7
+ data.tar.gz: a04ad3753758141ddf0bff915f3db526259fd70c71d9d8885b44f1a11712df6846f83b6b223abaa708490fdb68fc98adf51d3b95cd13296212af433d1c039bb5
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.5'
8
+ s.version = '0.0.6'
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Crowdskout", "Revv","Kyle Schutt"]
11
11
  s.homepage = "https://github.com/revvco/crowdskout"
@@ -26,7 +26,7 @@ module Crowdskout
26
26
  Services::ProfileService.get_profile(profile_id, collections)
27
27
  end
28
28
  def create_profile(profile)
29
- Services::ProfileService.create_profile(profile, params)
29
+ Services::ProfileService.create_profile(profile)
30
30
  end
31
31
  def create_profiles_bulk(profiles)
32
32
  Services::ProfileService.create_profiles_bulk(profiles)
@@ -13,18 +13,24 @@ module Crowdskout
13
13
  # @param [String] key_name - name of the collection
14
14
  # @param [Array] items - properties to create object from
15
15
  # @return [Collection]
16
- def self.create(key_name, items)
16
+ def self.create(props)
17
17
  obj = Collection.new
18
- obj.key_name = key_name
19
18
  obj.items = []
20
- if items
21
- items.each do |item|
22
- # item is a hash of fields
23
- obj.items << Components::Item.create(item)
19
+ props.each do |key, value|
20
+ obj.key_name = key
21
+ value.each do |collection|
22
+ obj.items << Components::Item.create(collection)
24
23
  end
25
24
  end
26
25
  obj
27
26
  end
27
+
28
+ # Hash override to generate the correct hash
29
+ def to_hash
30
+ {
31
+ key_name => items.collect(&:to_hash)
32
+ }
33
+ end
28
34
  end
29
35
  end
30
36
  end
@@ -14,16 +14,25 @@ module Crowdskout
14
14
  # @param [String] key_name - name of the Field
15
15
  # @param [Hash or String] value - properties to create object from
16
16
  # @return [Field]
17
- def self.create(key_name, value)
17
+ def self.create(props)
18
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
19
+ props.each do |key, value|
20
+ obj.key_name = key
21
+ if value.is_a?(Hash)
22
+ obj.value = Value.create(value)
23
+ else
24
+ obj.value = value.to_s
25
+ end
24
26
  end
25
27
  obj
26
28
  end
29
+
30
+ # Hash override to generate the correct hash
31
+ def to_hash
32
+ {
33
+ key_name => (value.is_a?(String) ? value : value.to_hash)
34
+ }
35
+ end
27
36
  end
28
37
  end
29
38
  end
@@ -23,12 +23,21 @@ module Crowdskout
23
23
  else
24
24
  # key is the name of the field
25
25
  # value is the field's value
26
- obj.fields << Components::Field.create(key, value)
26
+ obj.fields << Components::Field.create({key => value})
27
27
  end
28
28
  end
29
29
  end
30
30
  obj
31
31
  end
32
+
33
+ # Hash override to generate the correct hash
34
+ def to_hash
35
+ ret_val = { id: id }
36
+ fields.each do |field|
37
+ ret_val.merge! field.to_hash
38
+ end
39
+ ret_val
40
+ end
32
41
  end
33
42
  end
34
43
  end
@@ -22,7 +22,7 @@ module Crowdskout
22
22
  else
23
23
  # the key is the name of the collection
24
24
  # the value is an array of items
25
- obj.collections << Components::Collection.create(key, value)
25
+ obj.collections << Components::Collection.create({key => value})
26
26
  end
27
27
  end
28
28
  end
@@ -45,6 +45,15 @@ module Crowdskout
45
45
  @genders << gender
46
46
  end
47
47
 
48
+ # Hash override to generate the correct hash
49
+ def to_hash
50
+ ret_val = { id: id }
51
+ collections.each do |collection|
52
+ ret_val.merge! collection.to_hash
53
+ end
54
+ ret_val
55
+ end
56
+
48
57
  end
49
58
  end
50
59
  end
@@ -19,5 +19,5 @@
19
19
  # THE SOFTWARE.
20
20
 
21
21
  module Crowdskout
22
- VERSION = '0.0.5'
22
+ VERSION = '0.0.6'
23
23
  end
@@ -0,0 +1,41 @@
1
+ #
2
+ # attribute_spec.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
6
+
7
+ require 'spec_helper'
8
+
9
+ describe Crowdskout::Components::Attribute do
10
+ before do
11
+ @json_string = %[{
12
+ "id" : 1,
13
+ "name" : "Ready to set sail",
14
+ "type" : "Radio",
15
+ "locked" : false,
16
+ "options" : [
17
+ {
18
+ "id" : 1,
19
+ "value" : "Yes"
20
+ },
21
+ {
22
+ "id" : 2,
23
+ "value" : "No"
24
+ }
25
+ ]
26
+ }]
27
+ @hash = JSON.parse(@json_string)
28
+ end
29
+
30
+ it "creates a component" do
31
+ component = Crowdskout::Components::Attribute.create(@hash)
32
+ expect(component.name).to eq "Ready to set sail"
33
+ expect(component.type).to eq "Radio"
34
+ expect(component.locked).to eq false
35
+ expect(component.options.count).to eq 2
36
+ end
37
+ it "generates the correct json object" do
38
+ component = Crowdskout::Components::Attribute.create(@hash)
39
+ expect(JSON.parse(component.to_json)).to eq @hash
40
+ end
41
+ end
@@ -0,0 +1,32 @@
1
+ #
2
+ # field_options_spec.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
6
+
7
+ require 'spec_helper'
8
+
9
+ describe Crowdskout::Components::FieldOptions do
10
+ before do
11
+ @json_string = %[{
12
+ "collection" : "PhysicalAddresses",
13
+ "options" : [
14
+ {
15
+ "id" : 1,
16
+ "value" : "Lisbon"
17
+ }
18
+ ]
19
+ }]
20
+ @hash = JSON.parse(@json_string)
21
+ end
22
+
23
+ it "creates a field option" do
24
+ field_option = Crowdskout::Components::FieldOptions.create(@hash)
25
+ expect(field_option.collection).to eq "PhysicalAddresses"
26
+ expect(field_option.options.count).to eq 1
27
+ end
28
+ it "generates the correct json object" do
29
+ field_option = Crowdskout::Components::FieldOptions.create(@hash)
30
+ expect(JSON.parse(field_option.to_json)).to eq @hash
31
+ end
32
+ end
@@ -0,0 +1,42 @@
1
+ #
2
+ # collection_spec.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
6
+
7
+ require 'spec_helper'
8
+
9
+ describe Crowdskout::Components::Collection do
10
+ before do
11
+ @json_string = %[{
12
+ "Names" : [
13
+ {
14
+ "id" : 1,
15
+ "FullName" : "Mr. Ferdinand Magellan",
16
+ "NameTitle" : "Mr.",
17
+ "FirstName" : "Ferdinand",
18
+ "MiddleName" : "",
19
+ "LastName" : "Magellan",
20
+ "NameSuffix" : "",
21
+ "Gender" : {
22
+ "id" : 1,
23
+ "value" : "Male"
24
+ }
25
+ }
26
+ ]
27
+ }]
28
+ @hash = JSON.parse(@json_string)
29
+ end
30
+
31
+ it "creates a component" do
32
+ component = Crowdskout::Components::Collection.create(@hash)
33
+ expect(component.key_name).to eq "Names"
34
+ expect(component.items.count).to eq 1
35
+ component.items[0].should be_kind_of(Crowdskout::Components::Item)
36
+ expect(component.items[0].fields.count).to eq 7
37
+ end
38
+ it "generates the correct json object" do
39
+ component = Crowdskout::Components::Collection.create(@hash)
40
+ expect(JSON.parse(component.to_json)).to eq @hash
41
+ end
42
+ end
@@ -0,0 +1,49 @@
1
+ #
2
+ # field_spec.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
6
+
7
+ require 'spec_helper'
8
+
9
+ describe Crowdskout::Components::Field do
10
+ context "hash value" do
11
+ before do
12
+ @json_string = %[{
13
+ "Gender" : {
14
+ "id" : 1,
15
+ "value" : "Male"
16
+ }
17
+ }]
18
+ @hash = JSON.parse(@json_string)
19
+ end
20
+
21
+ it "creates a component" do
22
+ component = Crowdskout::Components::Field.create(@hash)
23
+ expect(component.key_name).to eq "Gender"
24
+ component.value.should be_kind_of(Crowdskout::Components::Value)
25
+ end
26
+ it "generates the correct json object" do
27
+ component = Crowdskout::Components::Field.create(@hash)
28
+ expect(JSON.parse(component.to_json)).to eq @hash
29
+ end
30
+ end
31
+ context "string value" do
32
+ before do
33
+ @json_string = %[{
34
+ "Gender" : "Male"
35
+ }]
36
+ @hash = JSON.parse(@json_string)
37
+ end
38
+
39
+ it "creates a component" do
40
+ component = Crowdskout::Components::Field.create(@hash)
41
+ expect(component.key_name).to eq "Gender"
42
+ expect(component.value).to eq "Male"
43
+ end
44
+ it "generates the correct json object" do
45
+ component = Crowdskout::Components::Field.create(@hash)
46
+ expect(JSON.parse(component.to_json)).to eq @hash
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,31 @@
1
+ #
2
+ # item_spec.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
6
+
7
+ require 'spec_helper'
8
+
9
+ describe Crowdskout::Components::Item do
10
+ before do
11
+ @json_string = %[{
12
+ "id" : 1,
13
+ "Gender" : {
14
+ "id" : 1,
15
+ "value" : "Male"
16
+ },
17
+ "TestValue" : "value"
18
+ }]
19
+ @hash = JSON.parse(@json_string)
20
+ end
21
+
22
+ it "creates a component" do
23
+ component = Crowdskout::Components::Item.create(@hash)
24
+ expect(component.id).to eq 1
25
+ component.fields[0].should be_kind_of(Crowdskout::Components::Field)
26
+ end
27
+ it "generates the correct json object" do
28
+ component = Crowdskout::Components::Item.create(@hash)
29
+ expect(JSON.parse(component.to_json)).to eq @hash
30
+ end
31
+ end
@@ -0,0 +1,55 @@
1
+ #
2
+ # profile_spec.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
6
+
7
+ require 'spec_helper'
8
+
9
+ describe Crowdskout::Components::Profile do
10
+ before do
11
+ @json_string = %[{
12
+ "id" : 1,
13
+ "Names" : [
14
+ {
15
+ "id" : 1,
16
+ "FullName" : "Mr. Ferdinand Magellan",
17
+ "NameTitle" : "Mr.",
18
+ "FirstName" : "Ferdinand",
19
+ "MiddleName" : "",
20
+ "LastName" : "Magellan",
21
+ "NameSuffix" : ""
22
+ }
23
+ ],
24
+ "Genders" : [
25
+ {
26
+ "id" : 1,
27
+ "Gender" : {
28
+ "id" : 1,
29
+ "value" : "Male"
30
+ },
31
+ "TestValue" : "value"
32
+ }
33
+ ]
34
+ }]
35
+ @hash = JSON.parse(@json_string)
36
+ end
37
+
38
+ it "creates a component" do
39
+ component = Crowdskout::Components::Profile.create(@hash)
40
+ expect(component.id).to eq 1
41
+ expect(component.collections.count).to eq 2
42
+ component.collections[0].should be_kind_of(Crowdskout::Components::Collection)
43
+ expect(component.collections[0].items.count).to eq 1
44
+ component.collections[0].items[0].should be_kind_of(Crowdskout::Components::Item)
45
+
46
+ expect(component.collections[0].items[0].fields.count).to eq 6
47
+ component.collections[0].items[0].fields[0].should be_kind_of(Crowdskout::Components::Field)
48
+
49
+ expect(component.collections[0].items[0].fields[0].value).to eq "Mr. Ferdinand Magellan"
50
+ end
51
+ it "generates the correct json object" do
52
+ component = Crowdskout::Components::Profile.create(@hash)
53
+ expect(JSON.parse(component.to_json)).to eq @hash
54
+ end
55
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # value_spec.rb
3
+ # Crowdskout
4
+ #
5
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
6
+
7
+ require 'spec_helper'
8
+
9
+ describe Crowdskout::Components::Value do
10
+ before do
11
+ @json_string = %[{
12
+ "id" : 1,
13
+ "value" : "Male"
14
+ }]
15
+ @hash = JSON.parse(@json_string)
16
+ end
17
+
18
+ it "creates a component" do
19
+ component = Crowdskout::Components::Value.create(@hash)
20
+ expect(component.id).to eq 1
21
+ expect(component.value).to eq "Male"
22
+ end
23
+ it "generates the correct json object" do
24
+ component = Crowdskout::Components::Value.create(@hash)
25
+ expect(JSON.parse(component.to_json)).to eq @hash
26
+ end
27
+ 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.5
4
+ version: 0.0.6
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-04 00:00:00.000000000 Z
13
+ date: 2016-05-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rest-client
@@ -118,6 +118,13 @@ files:
118
118
  - lib/crowdskout/util/helpers.rb
119
119
  - lib/crowdskout/version.rb
120
120
  - spec/crowdskout/auth/oauth2_spec.rb
121
+ - spec/crowdskout/components/attributes/attribute_spec.rb
122
+ - spec/crowdskout/components/fields/field_options_spec.rb
123
+ - spec/crowdskout/components/profiles/collection_spec.rb
124
+ - spec/crowdskout/components/profiles/field_spec.rb
125
+ - spec/crowdskout/components/profiles/item_spec.rb
126
+ - spec/crowdskout/components/profiles/profile_spec.rb
127
+ - spec/crowdskout/components/profiles/value_spec.rb
121
128
  - spec/crowdskout/services/attribute_service_spec.rb
122
129
  - spec/crowdskout/services/field_service_spec.rb
123
130
  - spec/crowdskout/services/profile_service_spec.rb
@@ -147,6 +154,13 @@ specification_version: 4
147
154
  summary: Crowdskout SDK for Ruby
148
155
  test_files:
149
156
  - spec/crowdskout/auth/oauth2_spec.rb
157
+ - spec/crowdskout/components/attributes/attribute_spec.rb
158
+ - spec/crowdskout/components/fields/field_options_spec.rb
159
+ - spec/crowdskout/components/profiles/collection_spec.rb
160
+ - spec/crowdskout/components/profiles/field_spec.rb
161
+ - spec/crowdskout/components/profiles/item_spec.rb
162
+ - spec/crowdskout/components/profiles/profile_spec.rb
163
+ - spec/crowdskout/components/profiles/value_spec.rb
150
164
  - spec/crowdskout/services/attribute_service_spec.rb
151
165
  - spec/crowdskout/services/field_service_spec.rb
152
166
  - spec/crowdskout/services/profile_service_spec.rb