crowdskout 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,83 @@
1
+ #
2
+ # attribute_service_spec.rb
3
+ #
4
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
5
+
6
+ require 'spec_helper'
7
+
8
+ describe Crowdskout::Services::AttributeService do
9
+ before(:each) do
10
+ @request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
11
+ end
12
+
13
+ describe "#get_attributes" do
14
+ it "returns an array of attributes" do
15
+ json = load_file('attributes_response.json')
16
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
17
+
18
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
19
+ RestClient.stub(:get).and_return(response)
20
+ attributes = Crowdskout::Services::AttributeService.get_attributes()
21
+ attribute = attributes.results[0]
22
+
23
+ attributes.should be_kind_of(Crowdskout::Components::ResultSet)
24
+ attribute.should be_kind_of(Crowdskout::Components::Attribute)
25
+ end
26
+ end
27
+
28
+ describe "#get_attribute" do
29
+ it "returns a attribute" do
30
+ json = load_file('attribute_response.json')
31
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
32
+
33
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
34
+ RestClient.stub(:get).and_return(response)
35
+ attribute = Crowdskout::Services::AttributeService.get_attribute(1)
36
+
37
+ attribute.should be_kind_of(Crowdskout::Components::Attribute)
38
+ end
39
+ end
40
+
41
+ describe "#create_attribute" do
42
+ it "adds a attribute" do
43
+ json = load_file('attribute_response.json')
44
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
45
+
46
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
47
+ RestClient.stub(:post).and_return(response)
48
+ new_attribute = Crowdskout::Components::Attribute.create(JSON.parse(json))
49
+ attribute = Crowdskout::Services::AttributeService.create_attribute(new_attribute)
50
+
51
+ attribute.should be_kind_of(Crowdskout::Components::Attribute)
52
+ attribute.type.should eq('Radio')
53
+ end
54
+ end
55
+
56
+ describe "#delete_attribute" do
57
+ it "deletes a attribute" do
58
+ attribute_id = 196
59
+ net_http_resp = Net::HTTPResponse.new(1.0, 204, 'No Content')
60
+
61
+ response = RestClient::Response.create('', net_http_resp, {}, @request)
62
+ RestClient.stub(:delete).and_return(response)
63
+
64
+ result = Crowdskout::Services::AttributeService.delete_attribute(attribute_id)
65
+ result.should be true
66
+ end
67
+ end
68
+
69
+ describe "#update_attribute" do
70
+ it "updates a attribute" do
71
+ json = load_file('attribute_response.json')
72
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
73
+
74
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
75
+ RestClient.stub(:put).and_return(response)
76
+ attribute = Crowdskout::Components::Attribute.create(JSON.parse(json))
77
+ result = Crowdskout::Services::AttributeService.update_attribute(attribute)
78
+
79
+ result.should be_kind_of(Crowdskout::Components::Attribute)
80
+ result.type.should eq('Radio')
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,27 @@
1
+ #
2
+ # field_service_spec.rb
3
+ #
4
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
5
+
6
+ require 'spec_helper'
7
+
8
+ describe Crowdskout::Services::FieldService do
9
+ before(:each) do
10
+ @request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
11
+ end
12
+
13
+ describe "#get_options_for_a_field" do
14
+ it "returns a field" do
15
+ json = load_file('field_response.json')
16
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
17
+
18
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
19
+ RestClient.stub(:get).and_return(response)
20
+ field = Crowdskout::Services::FieldService.get_options_for_a_field("AddressCity")
21
+
22
+ field.should be_kind_of(Crowdskout::Components::FieldOptions)
23
+ field.collection.should eq "PhysicalAddresses"
24
+ field.options[0].value.should eq "Lisbon"
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,116 @@
1
+ #
2
+ # profile_service_spec.rb
3
+ #
4
+ # Copyright (c) 2016 Kyle Schutt. All rights reserved.require 'spec_helper'
5
+
6
+ require 'spec_helper'
7
+
8
+ describe Crowdskout::Services::ProfileService do
9
+ before(:each) do
10
+ @request = double('http request', :user => nil, :password => nil, :url => 'http://example.com', :redirection_history => nil)
11
+ end
12
+
13
+ describe "#get_profile" do
14
+ it "returns a profile" do
15
+ json = load_file('profile_response.json')
16
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
17
+
18
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
19
+ RestClient.stub(:get).and_return(response)
20
+ profile = Crowdskout::Services::ProfileService.get_profile(1, "Names,Genders")
21
+
22
+ 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'
28
+ end
29
+ end
30
+
31
+ describe "#create_profile" do
32
+ it "adds a profile" do
33
+ json = load_file('profile_response.json')
34
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
35
+
36
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
37
+ RestClient.stub(:post).and_return(response)
38
+ new_profile = Crowdskout::Components::Profile.create(JSON.parse(json))
39
+ profile = Crowdskout::Services::ProfileService.create_profile(new_profile)
40
+
41
+ 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'
47
+ end
48
+ end
49
+
50
+ describe "#create_profiles_bulk" do
51
+ it "adds a profile" do
52
+ json = load_file('profile_bulk_response.json')
53
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
54
+
55
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
56
+ RestClient.stub(:post).and_return(response)
57
+ new_profile = Crowdskout::Components::Profile.create(JSON.parse(json))
58
+ profiles = []
59
+ body = JSON.parse(json)
60
+ body['data'].each do |profile|
61
+ profiles << Crowdskout::Components::Profile.create(profile)
62
+ end if body['data'].count > 0
63
+ profiles = Crowdskout::Services::ProfileService.create_profiles_bulk(profiles)
64
+ profile = profiles.results[0]
65
+
66
+ profiles.should be_kind_of(Crowdskout::Components::ResultSet)
67
+ 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'
71
+ end
72
+ end
73
+
74
+ describe "#update_profile" do
75
+ it "updates a profile" do
76
+ json = load_file('profile_response.json')
77
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
78
+
79
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
80
+ RestClient.stub(:put).and_return(response)
81
+ profile = Crowdskout::Components::Profile.create(JSON.parse(json))
82
+ result = Crowdskout::Services::ProfileService.update_profile(profile)
83
+
84
+ 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'
90
+ end
91
+ end
92
+
93
+ describe "#update_profiles_bulk" do
94
+ it "adds a profile" do
95
+ json = load_file('profile_bulk_response.json')
96
+ net_http_resp = Net::HTTPResponse.new(1.0, 200, 'OK')
97
+
98
+ response = RestClient::Response.create(json, net_http_resp, {}, @request)
99
+ RestClient.stub(:put).and_return(response)
100
+ new_profile = Crowdskout::Components::Profile.create(JSON.parse(json))
101
+ profiles = []
102
+ body = JSON.parse(json)
103
+ body['data'].each do |profile|
104
+ profiles << Crowdskout::Components::Profile.create(profile)
105
+ end if body['data'].count > 0
106
+ profiles = Crowdskout::Services::ProfileService.update_profiles_bulk(profiles)
107
+ profile = profiles.results[0]
108
+
109
+ 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'
114
+ end
115
+ end
116
+ end
metadata ADDED
@@ -0,0 +1,150 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: crowdskout
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
+ platform: ruby
6
+ authors:
7
+ - Crowdskout
8
+ - Revv
9
+ - Kyle Schutt
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2016-05-03 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rest-client
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1.6'
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: 1.6.7
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - "~>"
30
+ - !ruby/object:Gem::Version
31
+ version: '1.6'
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.6.7
35
+ - !ruby/object:Gem::Dependency
36
+ name: json
37
+ requirement: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '1.8'
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: 1.8.1
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - "~>"
50
+ - !ruby/object:Gem::Version
51
+ version: '1.8'
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 1.8.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: mime-types
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.25'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 1.25.1
65
+ type: :runtime
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '1.25'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.25.1
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.14'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.14'
89
+ description: Ruby library for interactions with Crowdskout v1 API
90
+ email: kyle@revv.co
91
+ executables: []
92
+ extensions: []
93
+ extra_rdoc_files: []
94
+ files:
95
+ - ".rspec"
96
+ - README.md
97
+ - crowdskout.gemspec
98
+ - lib/crowdskout.rb
99
+ - lib/crowdskout/api.rb
100
+ - lib/crowdskout/auth/oauth2.rb
101
+ - lib/crowdskout/components/attributes/attribute.rb
102
+ - lib/crowdskout/components/attributes/option.rb
103
+ - lib/crowdskout/components/component.rb
104
+ - lib/crowdskout/components/fields/field_options.rb
105
+ - lib/crowdskout/components/profiles/gender.rb
106
+ - lib/crowdskout/components/profiles/name.rb
107
+ - lib/crowdskout/components/profiles/profile.rb
108
+ - lib/crowdskout/components/result_set.rb
109
+ - lib/crowdskout/exceptions/oauth2_exception.rb
110
+ - lib/crowdskout/exceptions/service_exception.rb
111
+ - lib/crowdskout/services/attribute_service.rb
112
+ - lib/crowdskout/services/base_service.rb
113
+ - lib/crowdskout/services/field_service.rb
114
+ - lib/crowdskout/services/profile_service.rb
115
+ - lib/crowdskout/util/config.rb
116
+ - lib/crowdskout/util/helpers.rb
117
+ - lib/crowdskout/version.rb
118
+ - spec/crowdskout/auth/oauth2_spec.rb
119
+ - spec/crowdskout/services/attribute_service_spec.rb
120
+ - spec/crowdskout/services/field_service_spec.rb
121
+ - spec/crowdskout/services/profile_service_spec.rb
122
+ homepage: https://github.com/revvco/crowdskout
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubyforge_project:
142
+ rubygems_version: 2.2.2
143
+ signing_key:
144
+ specification_version: 4
145
+ summary: Crowdskout SDK for Ruby
146
+ test_files:
147
+ - spec/crowdskout/auth/oauth2_spec.rb
148
+ - spec/crowdskout/services/attribute_service_spec.rb
149
+ - spec/crowdskout/services/field_service_spec.rb
150
+ - spec/crowdskout/services/profile_service_spec.rb