pebble_timeline 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: fd338b2ea3b81ccb37288a2df5ce164e1926219f
4
+ data.tar.gz: b5b88e380890c434034fe2895d2cdf44ceb24867
5
+ SHA512:
6
+ metadata.gz: 9cb9b9214a901fd0b97a5311e41ae3ad82b78292c66e174e5910b91bbefcd0c7e443bba1ff0a3182610261833898e02a47d51197109f47f0733628eb71532e72
7
+ data.tar.gz: 97ccb85508bac62c0c094387d126b5a5099801babd18e0604115b14044c47680949590d3c09e3cb22ce35db176e87f49dc99c9fe1d76c768d88ed07fe89ff0f0
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in pebble_timeline.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Salim Hbeiliny
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # PebbleTimeline
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'pebble_timeline'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install pebble_timeline
20
+
21
+ ## Usage
22
+
23
+ ```
24
+ require 'pebble_timeline'
25
+
26
+ api = PebbleTimeline::API.new(ENV['PEBBLE_TIMELINE_API_KEY'])
27
+ pins = PebbleTimeline::Pins.new(api)
28
+
29
+ pins.create(id: "test-1", topics: 'test', time: "2015-06-10T08:01:10.229Z", layout: { shortTitle: 'test 1' })
30
+
31
+ pins.delete("test-1")
32
+ ```
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it ( https://github.com/[my-github-username]/pebble_timeline/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,27 @@
1
+ require 'active_support/configurable'
2
+ require 'active_support/inflector'
3
+ require 'faraday'
4
+ require 'json'
5
+ require 'roar/decorator'
6
+ require 'roar/json'
7
+
8
+ require "pebble_timeline/version"
9
+ require 'pebble_timeline/errors'
10
+
11
+ require 'pebble_timeline/middleware/error_detector'
12
+
13
+ require 'pebble_timeline/representer/action'
14
+ require 'pebble_timeline/representer/reminder'
15
+ require 'pebble_timeline/representer/layout'
16
+ require 'pebble_timeline/representer/notification'
17
+ require 'pebble_timeline/representer/pin'
18
+
19
+ require 'pebble_timeline/pins'
20
+ require 'pebble_timeline/api'
21
+
22
+ module PebbleTimeline
23
+ include ActiveSupport::Configurable
24
+
25
+ config_accessor(:api_key)
26
+ config_accessor(:base_url) { 'https://timeline-api.getpebble.com/v1/' }
27
+ end
@@ -0,0 +1,57 @@
1
+ module PebbleTimeline
2
+ class API
3
+ def initialize(api_key = nil)
4
+ raise ConfigMissingAPIKeyError, 'You must provide an API Key' unless PebbleTimeline.config.api_key || api_key
5
+
6
+ @api_key = PebbleTimeline.config.api_key || api_key
7
+ @base_url = PebbleTimeline.config.base_url
8
+ end
9
+
10
+ def call(url, http_method, params={})
11
+ response = send(http_method, url, params)
12
+ response.body
13
+ end
14
+
15
+ def connection
16
+ @connection ||= Faraday.new(url: @api_url) do |faraday|
17
+ faraday.headers['Content-Type'] = 'application/json'
18
+ faraday.headers['X-API-Key'] = @api_key
19
+ faraday.adapter Faraday.default_adapter
20
+ faraday.use PebbleTimeline::Middleware::ErrorDetector
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def post(path, params)
27
+ connection.post do |req|
28
+ req.url resource_url(path)
29
+ req.headers['X-User-Token'] = params.delete(:user_token) if params.has_key? :user_token
30
+ req.headers['X-Pin-Topics'] = params.delete(:topics) if params.has_key? :topics
31
+ req.body = params.to_json
32
+ end
33
+ end
34
+
35
+ def put(path, params)
36
+ connection.put do |req|
37
+ req.url resource_url(path)
38
+ req.headers['X-User-Token'] = params.delete(:user_token) if params.has_key? :user_token
39
+ req.headers['X-Pin-Topics'] = params.delete(:topics) if params.has_key? :topics
40
+ req.body = params.to_json
41
+ end
42
+ end
43
+
44
+ def get(path, params)
45
+ connection.get(resource_url(path), params)
46
+ end
47
+
48
+ def delete(path, params)
49
+ connection.delete(resource_url(path), params)
50
+ end
51
+
52
+ def resource_url(path)
53
+ "#{@base_url}#{path}"
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,12 @@
1
+ module PebbleTimeline
2
+
3
+ class APIError < StandardError
4
+ end
5
+
6
+ class ConfigError < StandardError
7
+ end
8
+
9
+ class ConfigMissingAPIKeyError < ConfigError
10
+ end
11
+
12
+ end
@@ -0,0 +1,15 @@
1
+ module PebbleTimeline
2
+ module Middleware
3
+ class ErrorDetector < Faraday::Middleware
4
+
5
+ def call(env)
6
+ @app.call(env).on_complete do |env|
7
+ unless (200..299).include? env[:status]
8
+ raise APIError, env[:body]
9
+ end
10
+ end
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,20 @@
1
+ module PebbleTimeline
2
+ class Pins
3
+ def initialize(master, type = 'shared')
4
+ @master = master
5
+ @type = type
6
+ end
7
+
8
+ def create(params = {})
9
+ @master.call("#{@type}/pins/#{params[:id]}", :put, params)
10
+ end
11
+
12
+ def update(id, params = {})
13
+ @master.call("#{@type}/pins/#{id}.json", :put, params)
14
+ end
15
+
16
+ def delete(id)
17
+ @master.call("#{@type}/pins/#{id}", :delete)
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module PebbleTimeline
2
+ class Action < OpenStruct
3
+ end
4
+
5
+ module Representer
6
+ class ActionRepresenter < Roar::Decorator
7
+ include Roar::JSON
8
+
9
+ property :title
10
+ property :type
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ module PebbleTimeline
2
+ class Layout < OpenStruct
3
+ end
4
+
5
+ module Representer
6
+ class LayoutRepresenter < Roar::Decorator
7
+ include Roar::JSON
8
+
9
+ property :type
10
+ property :title
11
+ property :shortTitle
12
+ property :subtitle
13
+ property :body
14
+ property :tinyIcon
15
+ property :smallIcon
16
+ property :largeIcon
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ module PebbleTimeline
2
+ class Notification < OpenStruct
3
+ end
4
+
5
+ module Representer
6
+ class NotificationRepresenter < Roar::Decorator
7
+ include Roar::JSON
8
+
9
+ property :layout, extend: LayoutRepresenter, class: Layout
10
+ property :time
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,20 @@
1
+ module PebbleTimeline
2
+ class Pin < OpenStruct
3
+ end
4
+
5
+ module Representer
6
+ class PinRepresenter < Roar::Decorator
7
+ include Roar::JSON
8
+
9
+ property :id
10
+ property :time
11
+ property :duration
12
+ property :createNotification, extend: NotificationRepresenter, class: Notification
13
+ property :updateNotification, extend: NotificationRepresenter, class: Notification
14
+ property :layout, extend: LayoutRepresenter, class: Layout
15
+
16
+ collection :reminders, extend: ReminderRepresenter, class: Reminder
17
+ collection :actions, extend: ActionRepresenter, class: Action
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,13 @@
1
+ module PebbleTimeline
2
+ class Reminder < OpenStruct
3
+ end
4
+
5
+ module Representer
6
+ class ReminderRepresenter < Roar::Decorator
7
+ include Roar::JSON
8
+
9
+ property :time
10
+ property :layout
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module PebbleTimeline
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'pebble_timeline/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "pebble_timeline"
8
+ spec.version = PebbleTimeline::VERSION
9
+ spec.authors = ["Salim Hbeiliny"]
10
+ spec.email = ["salim@hbeiliny.com"]
11
+ spec.summary = %q{A wrapper for the Pebble Timeline API}
12
+ spec.description = %q{This is a wrapper for the Pebble Timeline API documented here: http://developer.getpebble.com/guides/timeline/}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'activesupport', '~> 4.2'
22
+ spec.add_dependency 'faraday'
23
+ spec.add_dependency 'roar'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.7'
26
+ spec.add_development_dependency 'rake', '~> 10.0'
27
+ spec.add_development_dependency 'rspec', '~> 3'
28
+ spec.add_development_dependency 'webmock'
29
+ spec.add_development_dependency 'vcr'
30
+ spec.add_development_dependency 'pry'
31
+ end
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pebble_timeline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Salim Hbeiliny
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: roar
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.7'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.7'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3'
97
+ - !ruby/object:Gem::Dependency
98
+ name: webmock
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: vcr
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: 'This is a wrapper for the Pebble Timeline API documented here: http://developer.getpebble.com/guides/timeline/'
140
+ email:
141
+ - salim@hbeiliny.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - ".gitignore"
147
+ - Gemfile
148
+ - LICENSE.txt
149
+ - README.md
150
+ - Rakefile
151
+ - lib/pebble_timeline.rb
152
+ - lib/pebble_timeline/api.rb
153
+ - lib/pebble_timeline/errors.rb
154
+ - lib/pebble_timeline/middleware/error_detector.rb
155
+ - lib/pebble_timeline/pins.rb
156
+ - lib/pebble_timeline/representer/action.rb
157
+ - lib/pebble_timeline/representer/layout.rb
158
+ - lib/pebble_timeline/representer/notification.rb
159
+ - lib/pebble_timeline/representer/pin.rb
160
+ - lib/pebble_timeline/representer/reminder.rb
161
+ - lib/pebble_timeline/version.rb
162
+ - pebble_timeline.gemspec
163
+ homepage: ''
164
+ licenses:
165
+ - MIT
166
+ metadata: {}
167
+ post_install_message:
168
+ rdoc_options: []
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubyforge_project:
183
+ rubygems_version: 2.2.2
184
+ signing_key:
185
+ specification_version: 4
186
+ summary: A wrapper for the Pebble Timeline API
187
+ test_files: []