appboard 1.0.4 → 1.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.
- data/README.md +11 -11
- data/lib/appboard/exceptions.rb +25 -0
- data/lib/appboard/rest_api.rb +31 -64
- data/lib/appboard/version.rb +1 -1
- data/lib/appboard.rb +3 -13
- metadata +5 -4
data/README.md
CHANGED
@@ -45,9 +45,9 @@ or you could define API key in call block:
|
|
45
45
|
widget('some name here') {
|
46
46
|
uid "abcd1234"
|
47
47
|
|
48
|
-
data do
|
48
|
+
data do
|
49
49
|
# Data is here
|
50
|
-
|
50
|
+
end
|
51
51
|
}
|
52
52
|
}
|
53
53
|
|
@@ -74,14 +74,14 @@ There is several options how you could use API:
|
|
74
74
|
require 'rubygems'
|
75
75
|
require 'appboard'
|
76
76
|
|
77
|
-
Appboard.settings = { :apiKey => "
|
77
|
+
Appboard.settings = { :apiKey => "zxcv1234" }
|
78
78
|
|
79
79
|
widget = Appboard.widget('some name here') {
|
80
80
|
uid "abcd1234"
|
81
81
|
|
82
|
-
data do
|
82
|
+
data do
|
83
83
|
# Data is here
|
84
|
-
|
84
|
+
end
|
85
85
|
}
|
86
86
|
|
87
87
|
response = widget.push # push data to Dashboard on appboard.me
|
@@ -96,21 +96,21 @@ There is several options how you could use API:
|
|
96
96
|
require 'appboard'
|
97
97
|
|
98
98
|
Appboard.push {
|
99
|
-
apiKey "
|
99
|
+
apiKey "zxcv1234"
|
100
100
|
|
101
101
|
widget('widget1') {
|
102
102
|
uid "abcd1234"
|
103
103
|
|
104
|
-
data do
|
104
|
+
data do
|
105
105
|
# Data is here
|
106
|
-
|
106
|
+
end
|
107
107
|
}
|
108
108
|
widget('widget2') {
|
109
|
-
uid "
|
109
|
+
uid "poiu4321"
|
110
110
|
|
111
|
-
data do
|
111
|
+
data do
|
112
112
|
# Data is here
|
113
|
-
|
113
|
+
end
|
114
114
|
}
|
115
115
|
}
|
116
116
|
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Appboard
|
2
|
+
|
3
|
+
# Base Error class which all custom appboard exceptions inherit from.
|
4
|
+
# Rescuing Appboard::Error (or RuntimeError) will get all custom exceptions.
|
5
|
+
# If your dashboard is correctly configured and data is specified correctly, you should never expect to see any of these.
|
6
|
+
class Error < RuntimeError
|
7
|
+
|
8
|
+
# BadRequest is raised when a data for widget is specified incorrectly. Message usualy contains reference to documentation.
|
9
|
+
class BadRequest < Error
|
10
|
+
end
|
11
|
+
|
12
|
+
# NotFound is raised when a apiKey, dashboard or widget is not found.
|
13
|
+
class NotFound < Error
|
14
|
+
end
|
15
|
+
|
16
|
+
# ThrottleLimit is raised when throttle limit is reached (more details you could fine here - http://appboard.me/docs/restapi)
|
17
|
+
class ThrottleLimit < Error
|
18
|
+
end
|
19
|
+
|
20
|
+
# MissingConfiguration is raised when we're trying to run send data to widget or dashboard that needs configuration.
|
21
|
+
class MissingConfiguration < Error
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
data/lib/appboard/rest_api.rb
CHANGED
@@ -1,65 +1,32 @@
|
|
1
|
-
module Appboard
|
2
|
-
module RestAPI
|
3
|
-
|
4
|
-
def default_headers
|
5
|
-
{
|
6
|
-
:content_type => :json,
|
7
|
-
:accept => :json
|
8
|
-
}
|
9
|
-
end
|
10
|
-
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
raise e
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def post(uri, doc = nil, options = {})
|
38
|
-
opts = options.dup
|
39
|
-
payload = payload_from_doc(doc, opts)
|
40
|
-
begin
|
41
|
-
parse_response(RestClient.post(uri, payload, default_headers.merge(opts)), opts)
|
42
|
-
rescue Exception => e
|
43
|
-
if $DEBUG
|
44
|
-
raise "Error while sending a POST request #{uri}\npayload: #{payload.inspect}\n#{e}"
|
45
|
-
else
|
46
|
-
raise e
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
|
53
|
-
# Check if the provided doc is nil or special IO device or temp file. If not,
|
54
|
-
# encode it into a string.
|
55
|
-
def payload_from_doc(doc, opts = {})
|
56
|
-
(opts.delete(:raw) || doc.nil? || doc.is_a?(IO) || doc.is_a?(Tempfile)) ? doc : MultiJson.encode(doc)
|
57
|
-
end
|
58
|
-
|
59
|
-
# Parse the response provided.
|
60
|
-
def parse_response(result, opts = {})
|
61
|
-
opts.delete(:raw) ? result : MultiJson.decode(result, opts.update(:max_nesting => false))
|
62
|
-
end
|
63
|
-
|
64
|
-
end
|
1
|
+
module Appboard
|
2
|
+
module RestAPI
|
3
|
+
|
4
|
+
def default_headers
|
5
|
+
{
|
6
|
+
:content_type => :json,
|
7
|
+
:accept => :json
|
8
|
+
}
|
9
|
+
end
|
10
|
+
|
11
|
+
def put(url, payload)
|
12
|
+
json = JSON.generate(payload)
|
13
|
+
|
14
|
+
begin
|
15
|
+
RestClient.put url, json, default_headers
|
16
|
+
rescue RestClient::Exception => e
|
17
|
+
message = ""
|
18
|
+
|
19
|
+
begin
|
20
|
+
message = JSON.parse(e.response.body)["message"] if e.response.body
|
21
|
+
rescue JSON::ParserError => pe
|
22
|
+
# ignore
|
23
|
+
end
|
24
|
+
|
25
|
+
raise Error::BadRequest, message if e.http_code == 400
|
26
|
+
raise Error::NotFound, message if e.http_code == 404
|
27
|
+
raise Error::ThrottleLimit, message if e.http_code == 503
|
28
|
+
raise e
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
65
32
|
end
|
data/lib/appboard/version.rb
CHANGED
data/lib/appboard.rb
CHANGED
@@ -8,6 +8,7 @@ require 'appboard/version'
|
|
8
8
|
require 'appboard/rest_api'
|
9
9
|
require 'appboard/bootstrap'
|
10
10
|
require 'appboard/widget'
|
11
|
+
require 'appboard/exceptions'
|
11
12
|
|
12
13
|
module Appboard
|
13
14
|
|
@@ -72,20 +73,9 @@ module Appboard
|
|
72
73
|
|
73
74
|
def send(widget)
|
74
75
|
url = "#{@config[:url]}/#{@config[:version]}/#{@apiKey}/data/#{widget.uid}"
|
75
|
-
json = JSON.generate(widget.get_data)
|
76
|
-
|
77
|
-
#put url, json
|
78
|
-
|
79
|
-
|
80
|
-
begin
|
81
|
-
response = RestClient.put url, json, {:content_type => :json, :accept => :json}
|
82
|
-
puts response
|
83
|
-
rescue => e
|
84
|
-
abort "Failed to POST: #{e.message}"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
76
|
|
77
|
+
put url, widget.get_data
|
78
|
+
end
|
89
79
|
|
90
80
|
|
91
81
|
def handle_error(e)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appboard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 1.0.
|
9
|
+
- 5
|
10
|
+
version: 1.0.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- appboard.me
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-15 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- examples/singlenumner.rb
|
103
103
|
- lib/appboard.rb
|
104
104
|
- lib/appboard/bootstrap.rb
|
105
|
+
- lib/appboard/exceptions.rb
|
105
106
|
- lib/appboard/rest_api.rb
|
106
107
|
- lib/appboard/version.rb
|
107
108
|
- lib/appboard/widget.rb
|