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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 484a542107975d1eddde65b5457ddaa4c90d5be8
4
- data.tar.gz: 845a68b9301f4d9163368097bfa5a98e4dcdc2c9
3
+ metadata.gz: cff86a832993541cd2daceb983e0815d0ce04a85
4
+ data.tar.gz: a932aafed57edd407713b2facd08dace8d84d6bf
5
5
  SHA512:
6
- metadata.gz: 98c959380035e40cbd043e3d12840061e713b22c859885f7ff293d7a56bd126a3729dcec9b6be33dff47ffc8bfa06fd30940801dae584be6b67cb74c67d060b6
7
- data.tar.gz: 22fb4a91441992cd467335ed60c15a64a45754800ec4616d3b9bec53ddd4b196e0236376eee35fce3f636c58dad99e1eb7b384b7b92b8185836cbee6eb7a96fe
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'
@@ -0,0 +1,4 @@
1
+ module Unloq
2
+ class APIError::NotFoundError < Unloq::APIError
3
+ end
4
+ end
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
@@ -0,0 +1,11 @@
1
+ module Unloq
2
+ module Scoreboards
3
+
4
+ # View scoreboards
5
+
6
+ def scoreboards
7
+ get('/scoreboards')
8
+ end
9
+
10
+ end
11
+ end
data/lib/unloq/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Unloq
2
- VERSION = '0.0.4'
2
+ VERSION = '0.0.5'
3
3
  end
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
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: