unloq 0.0.2 → 0.0.3
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/lib/unloq.rb +1 -0
- data/lib/unloq/achievements.rb +37 -0
- data/lib/unloq/client.rb +14 -0
- data/lib/unloq/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7897418f6ca8c9fc33545aae4d46bccb0b54e56
|
4
|
+
data.tar.gz: 39d379fe3dbc9d56baaa4ea646757e59484e1d70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdde0af33b9ca715b957d9a42bb45d3c74b0257e167a4752e3f096d10d0207c83ade10c0a84ab071acef278d996b8fe1b2e47ffd8e0f33c4053618fd163a4e34
|
7
|
+
data.tar.gz: ce701c4a86e4739aa93f9bc7483c3edf60c23015be138bf65cd797251fdcc7de36688f1c27ebaf8d510f0877621f7855860fb63d01da54dd5fa08568329c76c2
|
data/lib/unloq.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Unloq
|
2
|
+
module Achievements
|
3
|
+
|
4
|
+
# Create an achievement via the Unloq API
|
5
|
+
#
|
6
|
+
# @param verb [String] verb The verb for which this achievement should be unlocked
|
7
|
+
# @param observation_count [Integer] observation_count The number of times the event must occur to unlock this achievement
|
8
|
+
# @param author [Unloq::Entity] An individual author, if passed this achievement will only be attainable by this author. Required if author_type is not defined.
|
9
|
+
# @param recipient [Unloq::Entity] An individual recipient that must be acted on to attain this achievement. Required if recipient_type is not defined.
|
10
|
+
# @param author_type [String] An individual author type, if passed this achievement will only be attaintable by authors of this type. Required if author is not defined.
|
11
|
+
# @param recipient_type [String] An individual recipient type that must be acted on to attain this achievement. Required if recipient is not defined.
|
12
|
+
# @param points [Integer] The number of points that will be awarded when this achievement is attained.
|
13
|
+
# @param image_path [String] An image path representing this achievement.
|
14
|
+
|
15
|
+
def create_achievement verb, observation_count,
|
16
|
+
author: nil, recipient: nil, author_type: nil, recipient_type: nil,
|
17
|
+
points: nil, image_path: nil
|
18
|
+
|
19
|
+
author_type, author_id = extract_entity_details(author, author_type)
|
20
|
+
recipient_type, recipient_id = extract_entity_details(recipient, recipient_type)
|
21
|
+
|
22
|
+
body_to_post = {
|
23
|
+
verb: verb,
|
24
|
+
observation_count: observation_count,
|
25
|
+
author_id: author_id,
|
26
|
+
author_type: author_type,
|
27
|
+
recipient_id: recipient_id,
|
28
|
+
recipient_type: recipient_type,
|
29
|
+
points: points,
|
30
|
+
image_path: image_path
|
31
|
+
}
|
32
|
+
|
33
|
+
post('/achievements', body_to_post)
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
end
|
data/lib/unloq/client.rb
CHANGED
@@ -2,6 +2,7 @@ module Unloq
|
|
2
2
|
class Client
|
3
3
|
|
4
4
|
include Events
|
5
|
+
include Achievements
|
5
6
|
|
6
7
|
attr_reader :api_key, :namespace
|
7
8
|
|
@@ -46,6 +47,19 @@ module Unloq
|
|
46
47
|
raise ArgumentError.new("Recipient must be an Unloq::Author or Unloq::Recipient") unless recipient.is_a?(Unloq::Entity)
|
47
48
|
end
|
48
49
|
|
50
|
+
#Extract entity type and ID from inclusion of either an Unloq::Entity or a *_type argument
|
51
|
+
def extract_entity_details entity = nil, entity_type = nil
|
52
|
+
if entity
|
53
|
+
validate_author(entity)
|
54
|
+
return [entity.type, entity.id]
|
55
|
+
else
|
56
|
+
unless entity_type
|
57
|
+
raise ArgumentError.new("Must include an author/recipient as an Unloq::Entity instance or include an author_type or recipient_type")
|
58
|
+
end
|
59
|
+
return [entity_type, nil]
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
49
63
|
private
|
50
64
|
|
51
65
|
# Return either the response body or raise a helpful error
|
data/lib/unloq/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Mueller
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-08-
|
11
|
+
date: 2014-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -133,6 +133,7 @@ files:
|
|
133
133
|
- LICENSE
|
134
134
|
- README.md
|
135
135
|
- lib/unloq.rb
|
136
|
+
- lib/unloq/achievements.rb
|
136
137
|
- lib/unloq/api_error.rb
|
137
138
|
- lib/unloq/client.rb
|
138
139
|
- lib/unloq/entities/author.rb
|