casual_helper 0.0.7 → 0.0.8
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.
- data/casual_helper.gemspec +1 -1
- data/lib/casual_helper/version.rb +1 -1
- data/lib/casual_helper.rb +72 -13
- metadata +4 -4
data/casual_helper.gemspec
CHANGED
@@ -5,7 +5,7 @@ Gem::Specification.new do |gem|
|
|
5
5
|
gem.authors = ["matthewspivey"]
|
6
6
|
gem.email = ["spivey.mathew@gmail.com"]
|
7
7
|
gem.description = %q{Casual gem}
|
8
|
-
gem.summary = %q{A casual gem,
|
8
|
+
gem.summary = %q{A casual gem, which probably isn't what you're looking for}
|
9
9
|
gem.homepage = ""
|
10
10
|
|
11
11
|
gem.files = `git ls-files`.split($\)
|
data/lib/casual_helper.rb
CHANGED
@@ -11,7 +11,7 @@ assumptions
|
|
11
11
|
* model classes should define variables and set them to default values
|
12
12
|
|
13
13
|
design decisions
|
14
|
-
* log
|
14
|
+
* on error: log error message and return nil
|
15
15
|
|
16
16
|
todo
|
17
17
|
* improve error handling
|
@@ -22,6 +22,13 @@ todo
|
|
22
22
|
JSON_CONTENT = {:content_type => :json, :accept => :json}
|
23
23
|
|
24
24
|
module CasualHelper
|
25
|
+
##
|
26
|
+
# CasualHelper::Api makes it easier to use the Casual Cloud REST API
|
27
|
+
#
|
28
|
+
# == Usage
|
29
|
+
#
|
30
|
+
# api = CasualHelper::Api.new 'http://localhost:9393'
|
31
|
+
#
|
25
32
|
class Api
|
26
33
|
|
27
34
|
def initialize(api_server)
|
@@ -44,23 +51,65 @@ module CasualHelper
|
|
44
51
|
}
|
45
52
|
end
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
54
|
+
#
|
55
|
+
# == Description
|
56
|
+
#
|
57
|
+
# Fetch all recent taps from the Casual Cloud API server
|
58
|
+
#
|
59
|
+
# Example:
|
60
|
+
#
|
61
|
+
# drops = api.get_taps #=> [{"id" => "0123456789abcdef01234567", ...}, ...]
|
62
|
+
#
|
63
|
+
# Returns nil on error.
|
64
|
+
#
|
65
|
+
# TODO - add limit parameter
|
66
|
+
#
|
67
|
+
def get_taps
|
68
|
+
get "#{@api_server.to_s}/v0/taps"
|
55
69
|
end
|
56
70
|
|
71
|
+
#
|
72
|
+
# == Description
|
73
|
+
#
|
74
|
+
# Fetch the tap with the specified ID
|
75
|
+
#
|
76
|
+
# @param tap_id If valid mongo ID string for an existing tap, the tap
|
77
|
+
# will be returned as a hash
|
78
|
+
#
|
79
|
+
# Example:
|
80
|
+
#
|
81
|
+
# tap = api.get_tap('0123456789abcdef01234567') #=> {"id" => "0123456789abcdef01234567", ...}
|
82
|
+
#
|
83
|
+
# Returns nil on error.
|
84
|
+
#
|
57
85
|
def get_tap(tap_id)
|
58
|
-
return if
|
86
|
+
return if are_invalid_mongo_key tap_id
|
59
87
|
get "#{@api_server.to_s}/v0/taps/#{tap_id}"
|
60
88
|
end
|
61
89
|
|
62
|
-
|
63
|
-
|
90
|
+
#
|
91
|
+
# == Description
|
92
|
+
#
|
93
|
+
# Fetch the drop with the specified IDs
|
94
|
+
#
|
95
|
+
# @param tap_id string containing the mongo ID of an existing tap
|
96
|
+
# @param drop_id string containing the mongo ID of an existing drop
|
97
|
+
#
|
98
|
+
# Example:
|
99
|
+
#
|
100
|
+
# tap = api.get_tap('0123456789abcdef01234567', 5) #=> {"id" => 5, "tap_id" => "7654321fedcba9876543210", ...}
|
101
|
+
#
|
102
|
+
# Returns nil on error.
|
103
|
+
#
|
104
|
+
def get_drop(tap_id, drop_id)
|
105
|
+
return if are_invalid_mongo_key tap_id
|
106
|
+
return if are_invalid drop_id
|
107
|
+
get "#{@api_server.to_s}/v0/taps/#{tap_id}/drops/#{drop_id.to_i}"
|
108
|
+
end
|
109
|
+
|
110
|
+
def add_tap(options)
|
111
|
+
return if are_invalid options
|
112
|
+
post "#{@api_server.to_s}/v0/taps", options
|
64
113
|
end
|
65
114
|
|
66
115
|
def add_drop(tap_id, options)
|
@@ -80,7 +129,7 @@ module CasualHelper
|
|
80
129
|
end
|
81
130
|
|
82
131
|
def get_user(id)
|
83
|
-
return if
|
132
|
+
return if are_invalid_mongo_key id
|
84
133
|
get "#{@api_server.to_s}/v0/users/#{id}"
|
85
134
|
end
|
86
135
|
|
@@ -152,6 +201,16 @@ module CasualHelper
|
|
152
201
|
end
|
153
202
|
end
|
154
203
|
|
204
|
+
def are_invalid_mongo_key(*params)
|
205
|
+
if params.nil? || params.any? {|param| param.nil? || !param.is_a?(String) || param.count != 24}
|
206
|
+
calling_method = caller[1][/`.*'/][1..-2]
|
207
|
+
p "Error in #{calling_method} - one or more parameters is nil - #{params.to_json}"
|
208
|
+
true
|
209
|
+
else
|
210
|
+
false
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
155
214
|
# logs error with method name of caller
|
156
215
|
# always returns nil
|
157
216
|
def log_error(url, message)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 8
|
9
|
+
version: 0.0.8
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- matthewspivey
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-09-
|
17
|
+
date: 2012-09-26 00:00:00 -04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -86,6 +86,6 @@ rubyforge_project:
|
|
86
86
|
rubygems_version: 1.3.6
|
87
87
|
signing_key:
|
88
88
|
specification_version: 3
|
89
|
-
summary: A casual gem,
|
89
|
+
summary: A casual gem, which probably isn't what you're looking for
|
90
90
|
test_files: []
|
91
91
|
|