badgeville 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ * 0.0.3
2
+
3
+ * Activity.rewards includes reward objects not reward definitions
4
+ * Reward has verb and threshold data for achievments type rewards
5
+ * Raise non json errors
data/README.md CHANGED
@@ -36,6 +36,7 @@ badgeville.reward_definitions
36
36
  ```
37
37
 
38
38
  * manually award some reward
39
+
39
40
  ```ruby
40
41
  badgeville.award "Best User"
41
42
  ```
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.2
1
+ 0.0.3
@@ -44,9 +44,8 @@ module Badgeville
44
44
 
45
45
  def get_activities
46
46
  response = make_call(:get, :activities)
47
- response["data"].inject([]) do |activities, activity_json|
48
- activities<< Activity.new(activity_json)
49
- activities
47
+ response["data"].map do |activity_json|
48
+ Activity.new(activity_json)
50
49
  end
51
50
  end
52
51
 
@@ -94,7 +93,7 @@ module Badgeville
94
93
  rescue => e
95
94
  if e.respond_to? :response
96
95
  data = JSON.parse(e.response)
97
- raise BadgevilleError.new(e.code, data["error"])
96
+ raise BadgevilleError.new(e.http_code, data["error"])
98
97
  else
99
98
  raise e
100
99
  end
@@ -149,8 +148,12 @@ module Badgeville
149
148
  json = JSON.parse(data)
150
149
  rescue => e
151
150
  if e.respond_to? :response
152
- data = JSON.parse(e.response)
153
- raise BadgevilleError.new(e.code, data["error"])
151
+ begin
152
+ data = JSON.parse(e.response)
153
+ raise BadgevilleError.new(e.code, data["error"])
154
+ rescue TypeError
155
+ raise e
156
+ end
154
157
  else
155
158
  raise e
156
159
  end
@@ -12,8 +12,8 @@ module Badgeville
12
12
  @user_id = json.delete("user_id")
13
13
  @points = json.delete("points").to_i
14
14
  @created_at = DateTime.parse(json.delete("created_at")).to_time
15
- @rewards = json.delete("rewards").inject([]) do |rewards, award|
16
- rewards << Reward.new(award["definition"])
15
+ @rewards = json.delete("rewards").map do |award|
16
+ Reward.new(award)
17
17
  end
18
18
  @meta = json.inject({}) do |meta, entry|
19
19
  k,v = entry
@@ -1,6 +1,7 @@
1
1
  module Badgeville
2
2
  class Reward
3
3
  attr_accessor :name, :hint, :image_url, :active, :earned_at, :id
4
+ attr_accessor :verb, :threshold
4
5
 
5
6
  # example:
6
7
  # {
@@ -50,6 +51,10 @@ module Badgeville
50
51
  @hint = json["hint"]
51
52
  @image_url = json["image_url"]
52
53
  @id = json["_id"]
54
+ if json["data"] && json["type"] == "achievement"
55
+ @verb = json["data"]["verb"]
56
+ @threshold = json["data"]["threshold"].to_i
57
+ end
53
58
  end
54
59
  end
55
60
  end
@@ -63,4 +63,15 @@ describe Badgeville::Reward do
63
63
  @reward.id.should == "4e4dfab6c47eed727b005c38"
64
64
  end
65
65
  end
66
+
67
+ context "when reward is an achievement (has data with verb and threshold)" do
68
+ before do
69
+ @reward = Badgeville::Reward.new(@parsed_json)
70
+ end
71
+
72
+ it "has verb adn threshold accessors" do
73
+ @reward.verb.should == "commented"
74
+ @reward.threshold.should == 2
75
+ end
76
+ end
66
77
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: badgeville
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-06 00:00:00.000000000 -07:00
12
+ date: 2011-09-12 00:00:00.000000000 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: json
17
- requirement: &2156516220 !ruby/object:Gem::Requirement
17
+ requirement: &2160633160 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *2156516220
25
+ version_requirements: *2160633160
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rest-client
28
- requirement: &2156515140 !ruby/object:Gem::Requirement
28
+ requirement: &2160631280 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *2156515140
36
+ version_requirements: *2160631280
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: rspec
39
- requirement: &2156514580 !ruby/object:Gem::Requirement
39
+ requirement: &2160629440 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 2.3.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *2156514580
47
+ version_requirements: *2160629440
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: bundler
50
- requirement: &2156513980 !ruby/object:Gem::Requirement
50
+ requirement: &2160627640 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: 1.0.0
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *2156513980
58
+ version_requirements: *2160627640
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: jeweler
61
- requirement: &2156512980 !ruby/object:Gem::Requirement
61
+ requirement: &2160625140 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ~>
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: 1.6.4
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *2156512980
69
+ version_requirements: *2160625140
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rcov
72
- requirement: &2156511560 !ruby/object:Gem::Requirement
72
+ requirement: &2160622960 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *2156511560
80
+ version_requirements: *2160622960
81
81
  description: Client for Badgeville's Core API v2. http://rules.badgeville.com
82
82
  email:
83
83
  executables: []
@@ -86,6 +86,7 @@ extra_rdoc_files:
86
86
  - README.md
87
87
  files:
88
88
  - .document
89
+ - CHANGELOG
89
90
  - Gemfile
90
91
  - Gemfile.lock
91
92
  - README.md
@@ -116,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
116
117
  version: '0'
117
118
  segments:
118
119
  - 0
119
- hash: -3222885892070570977
120
+ hash: -2793547173798113775
120
121
  required_rubygems_version: !ruby/object:Gem::Requirement
121
122
  none: false
122
123
  requirements: