friendly_score 0.0.1
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 +7 -0
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +43 -0
- data/README.md +29 -0
- data/Rakefile +17 -0
- data/friendly_score.gemspec +18 -0
- data/lib/friendly_score.rb +17 -0
- data/lib/friendly_score/api.rb +76 -0
- data/lib/friendly_score/endpoints/base.rb +39 -0
- data/lib/friendly_score/endpoints/show.rb +22 -0
- data/lib/friendly_score/endpoints/show_partner_user.rb +22 -0
- data/lib/friendly_score/endpoints/user_positive.rb +28 -0
- data/lib/friendly_score/endpoints/user_status.rb +24 -0
- data/lib/friendly_score/endpoints/users.rb +21 -0
- data/lib/friendly_score/errors.rb +8 -0
- data/lib/friendly_score/responder.rb +12 -0
- data/lib/friendly_score/user.rb +224 -0
- data/spec/cases/show_partner_user_spec.rb +33 -0
- data/spec/cases/show_spec.rb +74 -0
- data/spec/cases/user_positive_spec.rb +32 -0
- data/spec/cases/user_status_spec.rb +32 -0
- data/spec/cases/users_spec.rb +33 -0
- data/spec/fixtures/responses/show.json +1 -0
- data/spec/spec_helper.rb +16 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 228993f8b5f1b06c849e3982228d4546cd0aebbe
|
4
|
+
data.tar.gz: c01b9fc75ce7e2aae481736fe82b7f6efa2ca464
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 473209fd366251e1c6904558f6a3ac9aaa85475092b3a46c06e7e0a11068bdfec3403d5d94396d74ca4da2df493f8dfea7b9eeaf4e1b02f3bebc07da89b5f381
|
7
|
+
data.tar.gz: d317b80c15457e4c36a2826bd0da224c5b401a918c676b178c54906cd8b3296e56e9053818524c685e91acfd478e4981bce7784411dff4565f76562613603ea5
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
friendly_score (0.0.1)
|
5
|
+
multi_json (~> 1.10.0, >= 1.0.0)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
addressable (2.3.7)
|
11
|
+
crack (0.4.2)
|
12
|
+
safe_yaml (~> 1.0.0)
|
13
|
+
diff-lcs (1.2.5)
|
14
|
+
multi_json (1.10.1)
|
15
|
+
rake (10.4.2)
|
16
|
+
rspec (3.2.0)
|
17
|
+
rspec-core (~> 3.2.0)
|
18
|
+
rspec-expectations (~> 3.2.0)
|
19
|
+
rspec-mocks (~> 3.2.0)
|
20
|
+
rspec-core (3.2.1)
|
21
|
+
rspec-support (~> 3.2.0)
|
22
|
+
rspec-expectations (3.2.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.2.0)
|
25
|
+
rspec-mocks (3.2.1)
|
26
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
27
|
+
rspec-support (~> 3.2.0)
|
28
|
+
rspec-support (3.2.2)
|
29
|
+
safe_yaml (1.0.4)
|
30
|
+
webmock (1.20.4)
|
31
|
+
addressable (>= 2.3.6)
|
32
|
+
crack (>= 0.3.2)
|
33
|
+
yard (0.8.7.6)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
friendly_score!
|
40
|
+
rake (~> 10.4.0, >= 10.4.0)
|
41
|
+
rspec (~> 3.2.0, >= 3.2.0)
|
42
|
+
webmock (~> 1.20.0, >= 1.20.0)
|
43
|
+
yard (~> 0.8.7.0, >= 0)
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Friendly Score
|
2
|
+
|
3
|
+
Api wrapper for [friendlyscore.com](http://friendlyscore.com).
|
4
|
+
|
5
|
+
## Example usage:
|
6
|
+
|
7
|
+
require 'friendly_score'
|
8
|
+
|
9
|
+
# Create api instance
|
10
|
+
# the first argument is your appId and the second appSecret
|
11
|
+
api = FriendlyScore::API.new 1001, "3f4sgdfsgsdg5g5dsd"
|
12
|
+
|
13
|
+
# Get user 1005
|
14
|
+
api.show 1005
|
15
|
+
|
16
|
+
# Get partner user
|
17
|
+
api.show_partner_user "user.identificator"
|
18
|
+
|
19
|
+
# Set user 1002 as positive
|
20
|
+
api.user_positive 1002, 1
|
21
|
+
|
22
|
+
# Set user 1002 as negative
|
23
|
+
api.user_positive 1002, 0
|
24
|
+
|
25
|
+
# Set user status
|
26
|
+
api.user_status 1002, 2, "warning"
|
27
|
+
|
28
|
+
# Get list of all users
|
29
|
+
api.users
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# spec
|
2
|
+
begin
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
|
5
|
+
RSpec::Core::RakeTask.new(:spec)
|
6
|
+
|
7
|
+
task :default => :spec
|
8
|
+
rescue LoadError
|
9
|
+
end
|
10
|
+
|
11
|
+
# yard
|
12
|
+
require 'yard'
|
13
|
+
YARD::Rake::YardocTask.new do |t|
|
14
|
+
t.files = ['lib/**/*.rb']
|
15
|
+
t.stats_options = ['--list-undoc']
|
16
|
+
t.options = ["- README.md"]
|
17
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "friendly_score"
|
3
|
+
s.version = "0.0.1"
|
4
|
+
s.homepage = "http://www.friendlyscore.com"
|
5
|
+
s.author = "Krzysztof Zielonka"
|
6
|
+
s.email = "k.zielonka@software-project.pl"
|
7
|
+
s.summary = "friendly score api wrapper"
|
8
|
+
s.description = "api wrapper for friendlyscore.com platform"
|
9
|
+
s.files = `git ls-files`.split("\n")
|
10
|
+
s.license = "MIT"
|
11
|
+
|
12
|
+
s.add_runtime_dependency "multi_json", "~> 1.10.0", ">= 1.0.0"
|
13
|
+
|
14
|
+
s.add_development_dependency "rake", "~> 10.4.0", ">= 10.4.0"
|
15
|
+
s.add_development_dependency "rspec", "~> 3.2.0", ">= 3.2.0"
|
16
|
+
s.add_development_dependency "webmock", "~> 1.20.0", ">= 1.20.0"
|
17
|
+
s.add_development_dependency "yard", "~> 0.8.7.0", ">= 0"
|
18
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require "net/http"
|
2
|
+
require "multi_json"
|
3
|
+
|
4
|
+
require "friendly_score/errors"
|
5
|
+
require "friendly_score/responder"
|
6
|
+
require "friendly_score/user"
|
7
|
+
require "friendly_score/api"
|
8
|
+
|
9
|
+
require "friendly_score/endpoints/base"
|
10
|
+
require "friendly_score/endpoints/show"
|
11
|
+
require "friendly_score/endpoints/show_partner_user"
|
12
|
+
require "friendly_score/endpoints/user_positive"
|
13
|
+
require "friendly_score/endpoints/user_status"
|
14
|
+
require "friendly_score/endpoints/users"
|
15
|
+
|
16
|
+
module FriendlyScore
|
17
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module FriendlyScore
|
2
|
+
class API
|
3
|
+
attr_reader :application_id, :application_secret
|
4
|
+
|
5
|
+
# A new instance of API.
|
6
|
+
#
|
7
|
+
# @param application_id [Integer] application id
|
8
|
+
# @param application_secret [String] application secret
|
9
|
+
def initialize application_id, application_secret
|
10
|
+
@application_id = application_id
|
11
|
+
@application_secret = application_secret
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns user data (api: 'api/show')
|
15
|
+
#
|
16
|
+
# @param id [Integer] identificator of user
|
17
|
+
# @return [FriendlyScore::User]
|
18
|
+
def show id
|
19
|
+
endpoint = get_endpoint Endpoints::Show
|
20
|
+
endpoint.perform id
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns partner user
|
24
|
+
#
|
25
|
+
# @param partner_user_id [String] identificaotr of partner user
|
26
|
+
# @return [FriendlyScore::User]
|
27
|
+
def show_partner_user partner_user_id
|
28
|
+
endpoint = get_endpoint Endpoints::ShowPartnerUser
|
29
|
+
endpoint.perform partner_user_id
|
30
|
+
end
|
31
|
+
|
32
|
+
# Sets is user positive or not
|
33
|
+
#
|
34
|
+
# @param id [Integer] users identificator
|
35
|
+
# @param positive [Integer] 1 if user is positive, 0 if not
|
36
|
+
def user_positive id, positive
|
37
|
+
endpoint = get_endpoint Endpoints::UserPositive
|
38
|
+
endpoint.validate id, positive
|
39
|
+
endpoint.perform id, positive
|
40
|
+
end
|
41
|
+
|
42
|
+
# Sets users status with description
|
43
|
+
#
|
44
|
+
# @param id [Integer] users identificator
|
45
|
+
# @param status [Integer] any integer number
|
46
|
+
# @param status_description [String] status description
|
47
|
+
def user_status id, status, status_description
|
48
|
+
endpoint = get_endpoint Endpoints::UserStatus
|
49
|
+
endpoint.perform id, status, status_description
|
50
|
+
end
|
51
|
+
|
52
|
+
# List of all application users
|
53
|
+
#
|
54
|
+
# @return [List<FriendlyScore::User>] list of all users
|
55
|
+
def users
|
56
|
+
endpoint = get_endpoint Endpoints::Users
|
57
|
+
endpoint.perform
|
58
|
+
end
|
59
|
+
|
60
|
+
private
|
61
|
+
|
62
|
+
def get_endpoint endpoint_class
|
63
|
+
@endpoints ||= {}
|
64
|
+
unless @endpoints[endpoint_class]
|
65
|
+
@endpoints[endpoint_class] = endpoint_class.new(
|
66
|
+
@application_id, @application_secret, responder
|
67
|
+
)
|
68
|
+
end
|
69
|
+
@endpoints[endpoint_class]
|
70
|
+
end
|
71
|
+
|
72
|
+
def responder
|
73
|
+
@responder ||= Responder.new
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module FriendlyScore
|
2
|
+
module Endpoints
|
3
|
+
class Base
|
4
|
+
def initialize application_id, application_secret, responder
|
5
|
+
@application_id = application_id
|
6
|
+
@application_secret = application_secret
|
7
|
+
@responder = responder
|
8
|
+
end
|
9
|
+
|
10
|
+
def perform *args
|
11
|
+
code, body = make_request args
|
12
|
+
case code
|
13
|
+
when "200" then process_response body
|
14
|
+
when "404" then process_error body
|
15
|
+
else raise Errors::ServerError
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def make_request args
|
22
|
+
params = authorized_request_params args
|
23
|
+
@responder.get api_path, params
|
24
|
+
end
|
25
|
+
|
26
|
+
def authorized_request_params args
|
27
|
+
{
|
28
|
+
"appId" => @application_id,
|
29
|
+
"appSecret" => @application_secret
|
30
|
+
}.merge request_params *args
|
31
|
+
end
|
32
|
+
|
33
|
+
def process_error body
|
34
|
+
message = MultiJson.load(body)["message"]
|
35
|
+
raise Errors::NotFoundError.new message
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module FriendlyScore
|
2
|
+
module Endpoints
|
3
|
+
class Show < Base
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def process_response body
|
8
|
+
User.new MultiJson.load body
|
9
|
+
end
|
10
|
+
|
11
|
+
def api_path
|
12
|
+
"api/show.json"
|
13
|
+
end
|
14
|
+
|
15
|
+
def request_params id
|
16
|
+
{
|
17
|
+
"id" => id
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module FriendlyScore
|
2
|
+
module Endpoints
|
3
|
+
class ShowPartnerUser < Base
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def process_response body
|
8
|
+
User.new MultiJson.load body
|
9
|
+
end
|
10
|
+
|
11
|
+
def api_path
|
12
|
+
"api/show-partner-user.json"
|
13
|
+
end
|
14
|
+
|
15
|
+
def request_params partner_user_id
|
16
|
+
{
|
17
|
+
"partnerUserId" => partner_user_id
|
18
|
+
}
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module FriendlyScore
|
2
|
+
module Endpoints
|
3
|
+
class UserPositive < Base
|
4
|
+
def process_response body
|
5
|
+
nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def api_path
|
9
|
+
"api/user/positive"
|
10
|
+
end
|
11
|
+
|
12
|
+
def validate id, positive
|
13
|
+
unless [0, 1].include? positive
|
14
|
+
raise ValidationError.new "Argument 'positive' should be 0 or 1."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def request_params id, positive
|
21
|
+
{
|
22
|
+
"id" => id,
|
23
|
+
"positive" => positive
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module FriendlyScore
|
2
|
+
module Endpoints
|
3
|
+
class UserStatus < Base
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def process_response body
|
8
|
+
nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def api_path
|
12
|
+
"api/user/status.json"
|
13
|
+
end
|
14
|
+
|
15
|
+
def request_params id, status, status_description
|
16
|
+
{
|
17
|
+
"id" => id,
|
18
|
+
"status" => status,
|
19
|
+
"status_description" => status_description
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module FriendlyScore
|
2
|
+
module Endpoints
|
3
|
+
class Users < Base
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
def process_response body
|
8
|
+
users_hash = MultiJson.load body
|
9
|
+
users_hash.map { |_, user| FriendlyScore::User.new user }
|
10
|
+
end
|
11
|
+
|
12
|
+
def api_path
|
13
|
+
"api/users.json"
|
14
|
+
end
|
15
|
+
|
16
|
+
def request_params
|
17
|
+
{}
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module FriendlyScore
|
2
|
+
class Responder
|
3
|
+
def get path, params
|
4
|
+
uri = URI("https://social.friendlyscore.com/#{path}")
|
5
|
+
uri.query = URI.encode_www_form(params)
|
6
|
+
response = Net::HTTP.get_response uri
|
7
|
+
[response.code, response.body]
|
8
|
+
rescue MultiJson::ParseError
|
9
|
+
raise Errors::ParseError.new
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,224 @@
|
|
1
|
+
module FriendlyScore
|
2
|
+
class User
|
3
|
+
def initialize attributes
|
4
|
+
@attributes = attributes
|
5
|
+
end
|
6
|
+
|
7
|
+
def attributes
|
8
|
+
@attributes
|
9
|
+
end
|
10
|
+
|
11
|
+
# Id
|
12
|
+
#
|
13
|
+
# @return [Integer] users id
|
14
|
+
def id
|
15
|
+
@attributes["id"]
|
16
|
+
end
|
17
|
+
|
18
|
+
# Name
|
19
|
+
#
|
20
|
+
# @return [String] users name
|
21
|
+
def name
|
22
|
+
@attributes["name"]
|
23
|
+
end
|
24
|
+
|
25
|
+
# Address
|
26
|
+
#
|
27
|
+
# @return [String] address
|
28
|
+
def address
|
29
|
+
@attributes["address"]
|
30
|
+
end
|
31
|
+
|
32
|
+
# Age of the user
|
33
|
+
#
|
34
|
+
# @return [Integer] age of the user
|
35
|
+
def age
|
36
|
+
@attributes["age"].to_i
|
37
|
+
end
|
38
|
+
|
39
|
+
# City name
|
40
|
+
#
|
41
|
+
# @return [String] city name
|
42
|
+
def city_name
|
43
|
+
@attributes["city_name"]
|
44
|
+
end
|
45
|
+
|
46
|
+
# City population
|
47
|
+
#
|
48
|
+
# @return [String] city population
|
49
|
+
def city_population_50k
|
50
|
+
@attributes["city_population_50k"]
|
51
|
+
end
|
52
|
+
|
53
|
+
# Contact bank in 90 days
|
54
|
+
#
|
55
|
+
# @return [String] contact bank in 90 days
|
56
|
+
def contact_bank_in_90_days
|
57
|
+
@attributes["contact_bank_in_90_days"]
|
58
|
+
end
|
59
|
+
|
60
|
+
# Education best find
|
61
|
+
#
|
62
|
+
# @return [String] education best find
|
63
|
+
def education_best_find
|
64
|
+
@attributes["education_best_find"]
|
65
|
+
end
|
66
|
+
|
67
|
+
# Education average
|
68
|
+
#
|
69
|
+
# @return [String] education average
|
70
|
+
def education_average
|
71
|
+
@attributes["education_average"]
|
72
|
+
end
|
73
|
+
|
74
|
+
# Educations
|
75
|
+
#
|
76
|
+
# @return [String] educations
|
77
|
+
def educations
|
78
|
+
@attributes["educations"]
|
79
|
+
end
|
80
|
+
|
81
|
+
# Email
|
82
|
+
#
|
83
|
+
# @return [String] email
|
84
|
+
def email
|
85
|
+
@attributes["email"]
|
86
|
+
end
|
87
|
+
|
88
|
+
# Family
|
89
|
+
#
|
90
|
+
# @return [String] family
|
91
|
+
def family
|
92
|
+
@attributes["family"]
|
93
|
+
end
|
94
|
+
|
95
|
+
# Number of family members at home
|
96
|
+
#
|
97
|
+
# @return [Integer] number of family members at home
|
98
|
+
def family_members_in_home
|
99
|
+
@attributes["family_members_in_home"].to_i
|
100
|
+
end
|
101
|
+
|
102
|
+
# Friendly score
|
103
|
+
#
|
104
|
+
# @return [Integer] friendly score
|
105
|
+
def friendlyscore
|
106
|
+
@attributes["friendlyscore"]
|
107
|
+
end
|
108
|
+
|
109
|
+
# Facebook id
|
110
|
+
#
|
111
|
+
# @return [String] facebook id
|
112
|
+
def facebook_id
|
113
|
+
@attributes["facebook_id"]
|
114
|
+
end
|
115
|
+
|
116
|
+
# Gender of the user
|
117
|
+
#
|
118
|
+
# @return [Symbol] :male or :female
|
119
|
+
def gender
|
120
|
+
@attributes["gender"] == "male" ? :male : :female
|
121
|
+
end
|
122
|
+
|
123
|
+
# Number of kids
|
124
|
+
#
|
125
|
+
# @return [Integer] number of kids
|
126
|
+
def has_kids
|
127
|
+
@attributes["kids"].to_i
|
128
|
+
end
|
129
|
+
|
130
|
+
# Relationship
|
131
|
+
#
|
132
|
+
# @return [Boolean] true if user is in relationship, false if not
|
133
|
+
def in_relationship?
|
134
|
+
@attributes["in_relationship"] == "In a relationship"
|
135
|
+
end
|
136
|
+
|
137
|
+
# Is lead
|
138
|
+
#
|
139
|
+
# @return [Boolean] true if is lead, false in other case, nil if not set
|
140
|
+
def lead?
|
141
|
+
return nil unless @attributes["is_lead"]
|
142
|
+
@attributes["is_lead"].to_i == 1
|
143
|
+
end
|
144
|
+
|
145
|
+
# Is user set as positive
|
146
|
+
#
|
147
|
+
# @return [Boolean] true if user is positive, false if not, nil if not set
|
148
|
+
def positive?
|
149
|
+
return nil unless @attributes["is_positive"]
|
150
|
+
@attributes["is_positive"].to_i == 1
|
151
|
+
end
|
152
|
+
|
153
|
+
# Is working
|
154
|
+
#
|
155
|
+
# @return [Boolean] true if user is working, false if not, nil if not set
|
156
|
+
def working?
|
157
|
+
return nil unless @attributes["is_working"]
|
158
|
+
@attributes["is_working"].to_i == 1
|
159
|
+
end
|
160
|
+
|
161
|
+
# Loan amount
|
162
|
+
#
|
163
|
+
# @return [Integer] loan amount
|
164
|
+
def loan_amount
|
165
|
+
@attributes["loan_amount"]
|
166
|
+
end
|
167
|
+
|
168
|
+
# Loan currency
|
169
|
+
#
|
170
|
+
# @return [String] loan currency
|
171
|
+
def loan_currency
|
172
|
+
@attributes["loan_currency"]
|
173
|
+
end
|
174
|
+
|
175
|
+
# Loan description
|
176
|
+
#
|
177
|
+
# @return [String] loan description
|
178
|
+
def loan_description
|
179
|
+
@attributes["loan_description"]
|
180
|
+
end
|
181
|
+
|
182
|
+
# Loan duration
|
183
|
+
#
|
184
|
+
# @return [Integer] loan duration
|
185
|
+
def loan_duration_in_days
|
186
|
+
@attributes["loan_duration_in_days"]
|
187
|
+
end
|
188
|
+
|
189
|
+
# Mobile
|
190
|
+
#
|
191
|
+
# @return [String] mobile
|
192
|
+
def mobile
|
193
|
+
@attributes["mobile"]
|
194
|
+
end
|
195
|
+
|
196
|
+
# ScoreyourselfMobile
|
197
|
+
#
|
198
|
+
# @return [String] score yourself mobile
|
199
|
+
def scoreyourself_mobile
|
200
|
+
@attributes["scoreyourself_mobile"]
|
201
|
+
end
|
202
|
+
|
203
|
+
# Skills
|
204
|
+
#
|
205
|
+
# @return [String] skills
|
206
|
+
def skills
|
207
|
+
@attributes["skills"]
|
208
|
+
end
|
209
|
+
|
210
|
+
# Status of the user
|
211
|
+
#
|
212
|
+
# @return [Integer] status of the user
|
213
|
+
def status
|
214
|
+
@attributes["status"].to_i
|
215
|
+
end
|
216
|
+
|
217
|
+
# Status description
|
218
|
+
#
|
219
|
+
# @return [String] status description
|
220
|
+
def status_description
|
221
|
+
@attributes["status_description"]
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FriendlyScore do
|
4
|
+
subject{ FriendlyScore::API.new 1, "secret" }
|
5
|
+
|
6
|
+
describe "#show_partner_user" do
|
7
|
+
it "should raise access denied error" do
|
8
|
+
url = "http://social.friendlyscore.com/api/show-partner-user.json?appId=1&appSecret=secret&partnerUserId=user"
|
9
|
+
stub_request(:get, url).to_return({
|
10
|
+
:status => 404,
|
11
|
+
:body => "\{\"code\":404, \"message\":\"some message\"\}"
|
12
|
+
})
|
13
|
+
expect{
|
14
|
+
subject.show_partner_user "user"
|
15
|
+
}.to raise_error FriendlyScore::Errors::NotFoundError
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return user" do
|
19
|
+
url = "http://social.friendlyscore.com/api/show-partner-user.json?appId=1&appSecret=secret&partnerUserId=user"
|
20
|
+
stub_request(:get, url).to_return({
|
21
|
+
:status => 200,
|
22
|
+
:body => "\{\"id\":1\}"
|
23
|
+
})
|
24
|
+
|
25
|
+
result = nil
|
26
|
+
expect{
|
27
|
+
result = subject.show_partner_user "user"
|
28
|
+
}.to_not raise_error
|
29
|
+
expect( result ).to be_instance_of FriendlyScore::User
|
30
|
+
expect( result.id ).to eq 1
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FriendlyScore do
|
4
|
+
subject{ FriendlyScore::API.new 1, "secret" }
|
5
|
+
|
6
|
+
describe "#show" do
|
7
|
+
context "with invalid parameters" do
|
8
|
+
it "should raise not found error" do
|
9
|
+
url = "http://social.friendlyscore.com/api/show.json?appId=1&appSecret=secret&id=1"
|
10
|
+
stub_request(:get, url).to_return({
|
11
|
+
:status => 404,
|
12
|
+
:body => "\{\"code\":404, \"message\":\"some message\"\}"
|
13
|
+
})
|
14
|
+
|
15
|
+
expect{
|
16
|
+
subject.show 1
|
17
|
+
}.to raise_error FriendlyScore::Errors::NotFoundError
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise not found error" do
|
21
|
+
url = "http://social.friendlyscore.com/api/show.json?appId=1&appSecret=secret&id=1"
|
22
|
+
stub_request(:get, url).to_return({
|
23
|
+
:status => 500,
|
24
|
+
:body => "\{\"code\":404, \"message\":\"some message\"\}"
|
25
|
+
})
|
26
|
+
|
27
|
+
expect{
|
28
|
+
subject.show 1
|
29
|
+
}.to raise_error FriendlyScore::Errors::ServerError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with valid parameters" do
|
34
|
+
before :each do
|
35
|
+
url = "http://social.friendlyscore.com/api/show.json?appId=1&appSecret=secret&id=1"
|
36
|
+
stub_request(:get, url).to_return({
|
37
|
+
:status => 200,
|
38
|
+
:body => fixture('responses/show.json')
|
39
|
+
})
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should not raise any error" do
|
43
|
+
expect{
|
44
|
+
subject.show 1
|
45
|
+
}.to_not raise_error
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return instance of user" do
|
49
|
+
expect( subject.show 1 ).to be_instance_of FriendlyScore::User
|
50
|
+
end
|
51
|
+
|
52
|
+
{
|
53
|
+
:id => 1877,
|
54
|
+
:status => 2,
|
55
|
+
:status_description => "warning",
|
56
|
+
:name => "Emilian",
|
57
|
+
:age => 29,
|
58
|
+
:gender => :male,
|
59
|
+
:email => "mind_head@o2.pl",
|
60
|
+
:city_name => "London, United Kingdom",
|
61
|
+
:family_members_in_home => 1,
|
62
|
+
:has_kids => 0,
|
63
|
+
:friendlyscore => 49,
|
64
|
+
:positive? => true,
|
65
|
+
:working? => true,
|
66
|
+
:lead? => false
|
67
|
+
}.each do |key, value|
|
68
|
+
it "should return correct users '#{key}'" do
|
69
|
+
expect( subject.show(1).send(key) ).to eq value
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FriendlyScore do
|
4
|
+
subject{ FriendlyScore::API.new 1, "secret" }
|
5
|
+
|
6
|
+
describe "#user_positive" do
|
7
|
+
it "should raise access denied error" do
|
8
|
+
url = "http://social.friendlyscore.com/api/user/positive?appId=1&appSecret=secret&id=1&positive=1"
|
9
|
+
stub_request(:get, url).to_return({
|
10
|
+
:status => 404,
|
11
|
+
:body => "\{\"code\":404, \"message\":\"some message\"\}"
|
12
|
+
})
|
13
|
+
expect{
|
14
|
+
subject.user_positive 1, 1
|
15
|
+
}.to raise_error FriendlyScore::Errors::NotFoundError
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return nil" do
|
19
|
+
url = "http://social.friendlyscore.com/api/user/positive?appId=1&appSecret=secret&id=1&positive=1"
|
20
|
+
|
21
|
+
stub_request(:get, url).to_return({
|
22
|
+
:status => 200, :body => "\{\"id\":1\}"
|
23
|
+
})
|
24
|
+
|
25
|
+
result = nil
|
26
|
+
expect{
|
27
|
+
result = subject.user_positive 1, 1
|
28
|
+
}.to_not raise_error
|
29
|
+
expect( result ).to be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FriendlyScore do
|
4
|
+
subject{ FriendlyScore::API.new 1, "secret" }
|
5
|
+
|
6
|
+
describe "#user_status" do
|
7
|
+
it "should raise access denied error" do
|
8
|
+
url = "http://social.friendlyscore.com/api/user/status.json?appId=1&appSecret=secret&id=1&status=2&status_description=warning"
|
9
|
+
stub_request(:get, url).to_return({
|
10
|
+
:status => 404,
|
11
|
+
:body => "\{\"code\":404, \"message\":\"some message\"\}"
|
12
|
+
})
|
13
|
+
|
14
|
+
expect{
|
15
|
+
subject.user_status 1, 2, "warning"
|
16
|
+
}.to raise_error FriendlyScore::Errors::NotFoundError
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return nil" do
|
20
|
+
url = "http://social.friendlyscore.com/api/user/status.json?appId=1&appSecret=secret&id=1&status=2&status_description=warning"
|
21
|
+
stub_request(:get, url).to_return({
|
22
|
+
:status => 200, :body => "\{\"id\":1\}"
|
23
|
+
})
|
24
|
+
|
25
|
+
result = nil
|
26
|
+
expect{
|
27
|
+
result = subject.user_status 1, 2, "warning"
|
28
|
+
}.to_not raise_error
|
29
|
+
expect( result ).to be_nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe FriendlyScore do
|
4
|
+
subject{ FriendlyScore::API.new 1, "secret" }
|
5
|
+
|
6
|
+
describe "#users" do
|
7
|
+
it "should raise access denied error" do
|
8
|
+
url = "http://social.friendlyscore.com/api/users.json?appId=1&appSecret=secret"
|
9
|
+
stub_request(:get, url).to_return({
|
10
|
+
:status => 404,
|
11
|
+
:body => "\{\"code\":404, \"message\":\"some message\"\}"
|
12
|
+
})
|
13
|
+
|
14
|
+
expect{
|
15
|
+
subject.users
|
16
|
+
}.to raise_error FriendlyScore::Errors::NotFoundError
|
17
|
+
end
|
18
|
+
|
19
|
+
it "should return nil" do
|
20
|
+
url = "http://social.friendlyscore.com/api/users.json?appId=1&appSecret=secret"
|
21
|
+
stub_request(:get, url).to_return({
|
22
|
+
:status => 200,
|
23
|
+
:body => "\{\"id\":1\}"
|
24
|
+
})
|
25
|
+
|
26
|
+
result = nil
|
27
|
+
expect{
|
28
|
+
result = subject.users
|
29
|
+
}.to_not raise_error
|
30
|
+
expect( result ).to be_instance_of Array
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
{"id":1877,"partner_user_id":"emilian.siemsia","status":"2","status_description":"warning","is_positive":1,"name":"Emilian","lastname":"Siemsia","email":"mind_head@o2.pl","friendlyscore":49,"is_lead":0,"facebook_id":"100001586998830","education_best_find":"Master of Science (M.S.)","is_working":"1","educations":"[{\"degree\":\"Master of Science (M.S.)\",\"endDate\":{\"year\":2011},\"fieldOfStudy\":\"Automatics and Robotics\",\"id\":58257613,\"notes\":\"\\u00b7 Master Thesis: Implementation Intelligent Agents in SOAR Environment\",\"schoolName\":\"Uniwersity of Technology Wroclaw\",\"startDate\":{\"year\":2005}}]","age":"29","city_name":"London, United Kingdom","family_members_in_home":"1","gender":"male","has_kids":"0","in_relationship":"In a relationship"}
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'friendly_score'
|
2
|
+
require 'rspec'
|
3
|
+
require 'webmock/rspec'
|
4
|
+
|
5
|
+
WebMock.disable_net_connect!
|
6
|
+
|
7
|
+
def fixture_path
|
8
|
+
File.expand_path("../fixtures", __FILE__)
|
9
|
+
end
|
10
|
+
|
11
|
+
def fixture file
|
12
|
+
File.new(fixture_path + '/' + file)
|
13
|
+
end
|
14
|
+
|
15
|
+
RSpec.configure do |c|
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: friendly_score
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Krzysztof Zielonka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: multi_json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.10.0
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.0
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.10.0
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 1.0.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 10.4.0
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 10.4.0
|
43
|
+
type: :development
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: 10.4.0
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: 10.4.0
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rspec
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - "~>"
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: 3.2.0
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 3.2.0
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 3.2.0
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 3.2.0
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: webmock
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - "~>"
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 1.20.0
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.20.0
|
83
|
+
type: :development
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 1.20.0
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 1.20.0
|
93
|
+
- !ruby/object:Gem::Dependency
|
94
|
+
name: yard
|
95
|
+
requirement: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - "~>"
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: 0.8.7.0
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
type: :development
|
104
|
+
prerelease: false
|
105
|
+
version_requirements: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - "~>"
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: 0.8.7.0
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
description: api wrapper for friendlyscore.com platform
|
114
|
+
email: k.zielonka@software-project.pl
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- Gemfile
|
121
|
+
- Gemfile.lock
|
122
|
+
- README.md
|
123
|
+
- Rakefile
|
124
|
+
- friendly_score.gemspec
|
125
|
+
- lib/friendly_score.rb
|
126
|
+
- lib/friendly_score/api.rb
|
127
|
+
- lib/friendly_score/endpoints/base.rb
|
128
|
+
- lib/friendly_score/endpoints/show.rb
|
129
|
+
- lib/friendly_score/endpoints/show_partner_user.rb
|
130
|
+
- lib/friendly_score/endpoints/user_positive.rb
|
131
|
+
- lib/friendly_score/endpoints/user_status.rb
|
132
|
+
- lib/friendly_score/endpoints/users.rb
|
133
|
+
- lib/friendly_score/errors.rb
|
134
|
+
- lib/friendly_score/responder.rb
|
135
|
+
- lib/friendly_score/user.rb
|
136
|
+
- spec/cases/show_partner_user_spec.rb
|
137
|
+
- spec/cases/show_spec.rb
|
138
|
+
- spec/cases/user_positive_spec.rb
|
139
|
+
- spec/cases/user_status_spec.rb
|
140
|
+
- spec/cases/users_spec.rb
|
141
|
+
- spec/fixtures/responses/show.json
|
142
|
+
- spec/spec_helper.rb
|
143
|
+
homepage: http://www.friendlyscore.com
|
144
|
+
licenses:
|
145
|
+
- MIT
|
146
|
+
metadata: {}
|
147
|
+
post_install_message:
|
148
|
+
rdoc_options: []
|
149
|
+
require_paths:
|
150
|
+
- lib
|
151
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
requirements: []
|
162
|
+
rubyforge_project:
|
163
|
+
rubygems_version: 2.2.2
|
164
|
+
signing_key:
|
165
|
+
specification_version: 4
|
166
|
+
summary: friendly score api wrapper
|
167
|
+
test_files: []
|
168
|
+
has_rdoc:
|