unloq 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 94a280dda4b4c3f7cacaa84a69ac967338e71c46
4
- data.tar.gz: 0a4eb6f0d22a3a0572d5a12ae21ee82203990548
3
+ metadata.gz: d7897418f6ca8c9fc33545aae4d46bccb0b54e56
4
+ data.tar.gz: 39d379fe3dbc9d56baaa4ea646757e59484e1d70
5
5
  SHA512:
6
- metadata.gz: 59ca0165dd20edcddf0fcfbca4906e3289df3d8fa7cae99974f42ec61ed957a67f92f391aa44212dd6d40467704275e0253a5de97341e5a5a9b9060d2ec2f089
7
- data.tar.gz: 265f1581b9ca612941d84834a6fae99796096e6d5a842ff14ab97fcfce7a0e387b0921aa46b8e63b508b69780be11b3ebe76f2fcdcbf944bdffd4ccba991e766
6
+ metadata.gz: bdde0af33b9ca715b957d9a42bb45d3c74b0257e167a4752e3f096d10d0207c83ade10c0a84ab071acef278d996b8fe1b2e47ffd8e0f33c4053618fd163a4e34
7
+ data.tar.gz: ce701c4a86e4739aa93f9bc7483c3edf60c23015be138bf65cd797251fdcc7de36688f1c27ebaf8d510f0877621f7855860fb63d01da54dd5fa08568329c76c2
@@ -9,4 +9,5 @@ require 'unloq/entity'
9
9
  require 'unloq/entities/author'
10
10
  require 'unloq/entities/recipient'
11
11
  require 'unloq/events'
12
+ require 'unloq/achievements'
12
13
  require 'unloq/client'
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Unloq
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
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.2
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-22 00:00:00.000000000 Z
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