unloq 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.
- checksums.yaml +4 -4
- data/README.md +53 -0
- data/lib/unloq.rb +3 -0
- data/lib/unloq/api_error/not_found_error.rb +4 -0
- data/lib/unloq/client.rb +18 -0
- data/lib/unloq/events.rb +13 -0
- data/lib/unloq/ratings.rb +15 -0
- data/lib/unloq/scoreboards.rb +11 -0
- data/lib/unloq/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cff86a832993541cd2daceb983e0815d0ce04a85
|
4
|
+
data.tar.gz: a932aafed57edd407713b2facd08dace8d84d6bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86dc513b6731813b6da1442614dddfe27a186f66842d92d1cbf50104417a4c235dbf4fdb8e449cd2ee4dc62c12480c90f921dc7753b7d70334a588353db43e88
|
7
|
+
data.tar.gz: 511da23076ac5d92ee3c050a963e7e856887f3684ca7f62a77abb3d944edfd3fbcf0c9e869d36fe244ad12675d8e8eaa52053abda25c6d9eff3a739f8e4bc6cc
|
data/README.md
CHANGED
@@ -35,6 +35,59 @@ recipient = Unloq::Recipient.new(id: 13, type: 'User')
|
|
35
35
|
client.create_event(author, 'followed', recipient)
|
36
36
|
```
|
37
37
|
|
38
|
+
Lookup an event:
|
39
|
+
|
40
|
+
```ruby
|
41
|
+
author = Unloq::Author.new(id: 12, type: 'User')
|
42
|
+
recipient = Unloq::Recipient.new(id: 13, type: 'User')
|
43
|
+
|
44
|
+
# Note: this method will raise an Unloq::APIError::NotFoundError with
|
45
|
+
# a status of 404 if the event is not found
|
46
|
+
|
47
|
+
client.lookup_event(author, 'followed', recipient)
|
48
|
+
```
|
49
|
+
|
50
|
+
|
51
|
+
### Achievements
|
52
|
+
|
53
|
+
Create an achievement
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# See the documentation for additional keyword arguments
|
57
|
+
|
58
|
+
# Creating achievements based only on author and recipient types
|
59
|
+
# that are triggered after 2 observations
|
60
|
+
|
61
|
+
client.create_achievement('viewed-page', 2, author_type: 'User', recipient_type: 'Post')
|
62
|
+
|
63
|
+
# Creating achievements with author and recipient as specific entities
|
64
|
+
# that are triggered after 2 observations
|
65
|
+
|
66
|
+
author = Unloq::Author.new(id: 12, type: 'User')
|
67
|
+
recipient = Unloq::Recipient.new(id: 13, type: 'User')
|
68
|
+
client.create_achievement('poked', 2, author: author, recipient: recipient)
|
69
|
+
```
|
70
|
+
|
71
|
+
|
72
|
+
### Scoreboards
|
73
|
+
|
74
|
+
Fetch scoreboards for the namespace
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
client.scoreboards
|
78
|
+
```
|
79
|
+
|
80
|
+
|
81
|
+
### Ratings
|
82
|
+
|
83
|
+
Lookup ratings for an author in the namespace
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
author = Unloq::Author.new(id: 12, type: 'User')
|
87
|
+
|
88
|
+
client.lookup_author_ratings(author)
|
89
|
+
```
|
90
|
+
|
38
91
|
|
39
92
|
## Documentation
|
40
93
|
|
data/lib/unloq.rb
CHANGED
@@ -5,9 +5,12 @@ require 'faraday_middleware'
|
|
5
5
|
#Unloq Classes
|
6
6
|
require 'unloq/version'
|
7
7
|
require 'unloq/api_error'
|
8
|
+
require 'unloq/api_error/not_found_error'
|
8
9
|
require 'unloq/entity'
|
9
10
|
require 'unloq/entities/author'
|
10
11
|
require 'unloq/entities/recipient'
|
11
12
|
require 'unloq/events'
|
12
13
|
require 'unloq/achievements'
|
14
|
+
require 'unloq/scoreboards'
|
15
|
+
require 'unloq/ratings'
|
13
16
|
require 'unloq/client'
|
data/lib/unloq/client.rb
CHANGED
@@ -3,6 +3,8 @@ module Unloq
|
|
3
3
|
|
4
4
|
include Events
|
5
5
|
include Achievements
|
6
|
+
include Scoreboards
|
7
|
+
include Ratings
|
6
8
|
|
7
9
|
attr_reader :api_key, :namespace
|
8
10
|
|
@@ -36,6 +38,20 @@ module Unloq
|
|
36
38
|
format_response_or_raise_error(response)
|
37
39
|
end
|
38
40
|
|
41
|
+
# Make a get request to the Unloq API
|
42
|
+
#
|
43
|
+
# @param base_endpoint [String] The base resource endpoint, e.g. /events
|
44
|
+
# @param resource_scope [String] The scope of the resource endpoint, e.g. /User/1/login/User/1
|
45
|
+
|
46
|
+
def get base_endpoint, resource_scope = nil
|
47
|
+
|
48
|
+
response = connection.get do |req|
|
49
|
+
req.url "#{base_endpoint}/#{api_key}/#{namespace}#{resource_scope}"
|
50
|
+
end
|
51
|
+
|
52
|
+
format_response_or_raise_error(response)
|
53
|
+
end
|
54
|
+
|
39
55
|
|
40
56
|
# Validate that any author used is of the appropriate type
|
41
57
|
def validate_author author
|
@@ -67,6 +83,8 @@ module Unloq
|
|
67
83
|
def format_response_or_raise_error response
|
68
84
|
if response.status / 100 == 2
|
69
85
|
response.body
|
86
|
+
elsif response.status == 404
|
87
|
+
raise Unloq::APIError::NotFoundError.new(response.status, response.body)
|
70
88
|
else
|
71
89
|
raise Unloq::APIError.new(response.status, response.body)
|
72
90
|
end
|
data/lib/unloq/events.rb
CHANGED
@@ -24,5 +24,18 @@ module Unloq
|
|
24
24
|
post('/events', body_to_post)
|
25
25
|
end
|
26
26
|
|
27
|
+
# Lookup an event via the Unloq API
|
28
|
+
#
|
29
|
+
# @param author [Unloq::Entity] Author of the event you want to look up
|
30
|
+
# @param verb [String] Verb of the event you want to look up
|
31
|
+
# @param recipient [Unloq::Entity] Recipient of the event you want to look up
|
32
|
+
|
33
|
+
def lookup_event author, verb, recipient
|
34
|
+
validate_author(author)
|
35
|
+
validate_recipient(recipient)
|
36
|
+
|
37
|
+
get('/events', "/#{author.type}/#{author.id}/#{verb}/#{recipient.type}/#{recipient.id}")
|
38
|
+
end
|
39
|
+
|
27
40
|
end
|
28
41
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Unloq
|
2
|
+
module Ratings
|
3
|
+
|
4
|
+
# Fetch the ratings for an author
|
5
|
+
#
|
6
|
+
# @param author [Unloq::Entity] The author for which you want to retrieve ratings
|
7
|
+
|
8
|
+
def lookup_author_ratings author
|
9
|
+
validate_author(author)
|
10
|
+
|
11
|
+
get('/ratings', "/#{author.id}")
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/lib/unloq/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unloq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Mueller
|
@@ -135,11 +135,14 @@ files:
|
|
135
135
|
- lib/unloq.rb
|
136
136
|
- lib/unloq/achievements.rb
|
137
137
|
- lib/unloq/api_error.rb
|
138
|
+
- lib/unloq/api_error/not_found_error.rb
|
138
139
|
- lib/unloq/client.rb
|
139
140
|
- lib/unloq/entities/author.rb
|
140
141
|
- lib/unloq/entities/recipient.rb
|
141
142
|
- lib/unloq/entity.rb
|
142
143
|
- lib/unloq/events.rb
|
144
|
+
- lib/unloq/ratings.rb
|
145
|
+
- lib/unloq/scoreboards.rb
|
143
146
|
- lib/unloq/version.rb
|
144
147
|
homepage: http://github.com/mattmueller/unloq
|
145
148
|
licenses:
|