appboard 1.0.0

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/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 appboard.me
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
File without changes
@@ -0,0 +1,22 @@
1
+ module Appboard
2
+ module Bootstrap
3
+ def default_settings
4
+ url = URI.parse(ENV["APPBOARD_API_URL"] || 'http://api.appboard.me')
5
+ {
6
+ :url => url,
7
+ :version => 'v1',
8
+ :logging => false
9
+ }
10
+ rescue Object => e
11
+ raise "invalid APPBOARD_API_URL: (#{url.inspect}) #{e.class} -> #{e.message}"
12
+ end
13
+
14
+ def settings
15
+ @@settings ||= default_settings
16
+ end
17
+
18
+ def settings=(settings_hash)
19
+ @@settings = default_settings.update(settings_hash)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,65 @@
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 get(uri, options = {})
12
+ begin
13
+ parse_response(RestClient.get(uri, default_headers), options.dup)
14
+ rescue => e
15
+ if $DEBUG
16
+ raise "Error while sending a GET request #{uri}\n: #{e}"
17
+ else
18
+ raise e
19
+ end
20
+ end
21
+ end
22
+
23
+ def put(uri, doc = nil, options = {})
24
+ opts = options.dup
25
+ payload = payload_from_doc(doc, opts)
26
+ begin
27
+ parse_response(RestClient.put(uri, payload, default_headers.merge(opts)), opts)
28
+ rescue Exception => e
29
+ if $DEBUG
30
+ raise "Error while sending a PUT request #{uri}\npayload: #{payload.inspect}\n#{e}"
31
+ else
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
65
+ end
@@ -0,0 +1,9 @@
1
+ module Appboard #:nodoc:
2
+ module Version #:nodoc:
3
+ MAJOR = 1
4
+ MINOR = 0
5
+ TINY = 0
6
+
7
+ STRING = [MAJOR, MINOR, TINY].join('.')
8
+ end
9
+ end
@@ -0,0 +1,32 @@
1
+ module Appboard
2
+ # Defines widget
3
+ class Widget
4
+ def initialize(name, &block)
5
+ @name = name
6
+ instance_eval(&block)
7
+ end
8
+
9
+ def name
10
+ @name
11
+ end
12
+
13
+ def uid(value = nil)
14
+ @uid = value unless value.nil?
15
+ @uid
16
+ end
17
+
18
+ def type(value = nil)
19
+ @type = value unless value.nil?
20
+ @type
21
+ end
22
+
23
+ def data(&block)
24
+ @data = block if block_given?
25
+ @data
26
+ end
27
+
28
+ def get_data
29
+ @data.call()
30
+ end
31
+ end
32
+ end
data/lib/appboard.rb ADDED
@@ -0,0 +1,107 @@
1
+ require 'uri'
2
+ require 'json' unless defined? ActiveSupport::JSON
3
+ require 'restclient'
4
+
5
+ $:.unshift File.dirname(__FILE__)
6
+
7
+ require 'appboard/version'
8
+ require 'appboard/rest_api'
9
+ require 'appboard/bootstrap'
10
+ require 'appboard/widget'
11
+
12
+ module Appboard
13
+
14
+ class << self
15
+ @@widgets = {}
16
+
17
+ include Appboard::Bootstrap
18
+ include Appboard::RestAPI
19
+
20
+ # Define API key
21
+ def apiKey(value = nil)
22
+ @apiKey = value unless value.nil?
23
+ @apiKey
24
+ end
25
+
26
+ # Start the appboard loop
27
+ #
28
+ # appboard.start {
29
+ # # Do stuff in here
30
+ # }
31
+ #
32
+ # == Options
33
+ # * :apiKey => 'API key'
34
+ # * :logging => false
35
+ #
36
+ # Refer to default config below for how to set these as defaults
37
+ #
38
+ def start(options = {}, &block)
39
+ @config = settings.update(options)
40
+
41
+ self.instance_eval(&block) if block_given?
42
+ end
43
+
44
+ # Define a widget. May be called inside start loop or separately
45
+ #
46
+ # widget('name') {
47
+ # data {
48
+ # # Data is here
49
+ # }
50
+ # }
51
+ #
52
+ def widget(widget_name)
53
+ if block_given?
54
+ block = Proc.new
55
+ widget = register_widget(widget_name, &block)
56
+ send(widget)
57
+ else
58
+ widget = @@widgets[widget_name.to_s]
59
+
60
+ raise ArgumentError, "Widget is not defined, to define new widget you must supply a block as the last argument" if widget.nil?
61
+ end
62
+ widget
63
+ end
64
+
65
+ def register_widget(widget_name, &block)
66
+ widget = Widget.new(widget_name, &block)
67
+
68
+ ((@@widgets[widget_name.to_s] ||= []) << widget).uniq!
69
+ widget
70
+ end
71
+
72
+
73
+ def send(widget)
74
+ url = "#{@config[:url]}/#{@config[:version]}/#{@apiKey}/#{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
+
89
+
90
+
91
+ def handle_error(e)
92
+ log.error "#{e.class}: #{e.message}"#, :exception => e
93
+ e.backtrace.each do |line|
94
+ log.error line
95
+ end
96
+ end
97
+
98
+ def log
99
+ @@log ||= Logger.new($stdout)
100
+ end
101
+
102
+ def log=(log)
103
+ @@log = log
104
+ end
105
+
106
+ end
107
+ end
data/lib/test.rb ADDED
@@ -0,0 +1,19 @@
1
+ require 'rubygems'
2
+ require './appboard'
3
+
4
+ Appboard.start {
5
+ apiKey 'wOUpOJeOozcgPdZa'
6
+
7
+ widget('test') {
8
+ uid "weXtrkUwSeZGvcRK"
9
+
10
+ data do
11
+ {
12
+ :current => 120
13
+ }
14
+ end
15
+ }
16
+ }
17
+
18
+
19
+ Appboard.widget('test')
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: appboard
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - appboard.me
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-06-24 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ prerelease: false
23
+ name: rake
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - "="
28
+ - !ruby/object:Gem::Version
29
+ hash: 49
30
+ segments:
31
+ - 0
32
+ - 8
33
+ - 7
34
+ version: 0.8.7
35
+ requirement: *id001
36
+ type: :runtime
37
+ - !ruby/object:Gem::Dependency
38
+ prerelease: false
39
+ name: git
40
+ version_requirements: &id002 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ hash: 21
46
+ segments:
47
+ - 1
48
+ - 2
49
+ - 5
50
+ version: 1.2.5
51
+ requirement: *id002
52
+ type: :runtime
53
+ - !ruby/object:Gem::Dependency
54
+ prerelease: false
55
+ name: bundler
56
+ version_requirements: &id003 !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ hash: 15
62
+ segments:
63
+ - 1
64
+ - 0
65
+ version: "1.0"
66
+ requirement: *id003
67
+ type: :runtime
68
+ - !ruby/object:Gem::Dependency
69
+ prerelease: false
70
+ name: rest-client
71
+ version_requirements: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ requirement: *id004
81
+ type: :development
82
+ description: Simple and opinionated interface on top of RESTful HTTP API for pushing your data to appboard.me
83
+ email: eugene@appboard.me
84
+ executables: []
85
+
86
+ extensions: []
87
+
88
+ extra_rdoc_files:
89
+ - LICENSE.txt
90
+ - README
91
+ files:
92
+ - lib/appboard.rb
93
+ - lib/appboard/bootstrap.rb
94
+ - lib/appboard/rest_api.rb
95
+ - lib/appboard/version.rb
96
+ - lib/appboard/widget.rb
97
+ - lib/test.rb
98
+ - LICENSE.txt
99
+ - README
100
+ has_rdoc: true
101
+ homepage: https://github.com/appboard/appboard
102
+ licenses: []
103
+
104
+ post_install_message:
105
+ rdoc_options: []
106
+
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ hash: 3
124
+ segments:
125
+ - 0
126
+ version: "0"
127
+ requirements: []
128
+
129
+ rubyforge_project:
130
+ rubygems_version: 1.3.7
131
+ signing_key:
132
+ specification_version: 3
133
+ summary: API interface on top of RESTful HTTP API for pushing your data to appboard.me
134
+ test_files: []
135
+