remindrr 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1eb16d03dfe35e4fff4c4feae5a11f80374a619f
4
+ data.tar.gz: c351fc256d8752090ca8785346639840c422402d
5
+ SHA512:
6
+ metadata.gz: 71d6774a1769c40737e75fbcf38ef8e2d081bcad4a6fec16f731d7d6205a77ce0f693b06e9df6911a30af28806d25e798187ab0bc373a901fcad78843595e91b
7
+ data.tar.gz: 7a332f7a582ef2b31efc688916d3ea05ba8119c97b32898f01e9dad1b52d43a846199aa3f301759005956760fb6e1810efc72267c29bc729b0439b23cfec46f5
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.0
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in remindrr.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Irakli Lekishvili
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ [![Build Status](https://travis-ci.org/lekishvili/remindrr-ruby.svg?branch=master)](https://travis-ci.org/lekishvili/remindrr-ruby)
2
+ # Remindrr
3
+
4
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/remindrr`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+
6
+ TODO: Delete this and the text above, and describe your gem
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ ```ruby
13
+ gem 'remindrr'
14
+ ```
15
+
16
+ And then execute:
17
+
18
+ $ bundle
19
+
20
+ Or install it yourself as:
21
+
22
+ $ gem install remindrr
23
+
24
+ ## Usage
25
+
26
+ TODO: Write usage instructions here
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/remindrr.
37
+
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "remindrr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ require 'faraday'
2
+
3
+ module FaradayMiddleware
4
+ class RaiseHttpException < Faraday::Middleware
5
+ def call(env)
6
+ @app.call(env).on_complete do |response|
7
+ case response[:status].to_i
8
+ when 401
9
+ raise Remindrr::Unauthorized
10
+ when 404
11
+ raise Remindrr::NotFound
12
+ when 400
13
+ raise Remindrr::BadRequest, error_message_400(response)
14
+ end
15
+ end
16
+ end
17
+
18
+ def initialize(app)
19
+ super app
20
+ @parser = nil
21
+ end
22
+
23
+ private
24
+
25
+ def error_message_400(response)
26
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]} #{response[:body]}"
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,3 @@
1
+ Remindrr.configure do |config|
2
+ config.client_secret = ENV['CLIENT_SECRET']
3
+ end
@@ -0,0 +1,7 @@
1
+ class RemindrrGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('..', __FILE__)
3
+
4
+ def create_remindrr_initializer
5
+ copy_file 'initializer.rb', 'config/initializers/remindrr.rb'
6
+ end
7
+ end
data/lib/remindrr.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'faraday'
2
+
3
+ require 'remindrr/version'
4
+ require 'remindrr/configuration'
5
+ require 'remindrr/error'
6
+ require 'remindrr/connection'
7
+ require 'remindrr/request'
8
+ require 'remindrr/server'
9
+ require 'remindrr/app'
10
+ require 'remindrr/reminder'
11
+
12
+ module Remindrr
13
+ def self.configure
14
+ yield config
15
+ end
16
+
17
+ def self.config
18
+ @config ||= Configuration.new
19
+ end
20
+
21
+ def self.config=(config)
22
+ @config = config
23
+ end
24
+
25
+ configure do |config|
26
+ config.client_secret = ENV['CLIENT_SECRET']
27
+ end
28
+ end
@@ -0,0 +1,48 @@
1
+ module Remindrr
2
+ class App
3
+ extend Request
4
+
5
+ attr_accessor :id, :name, :endpoint, :created_at, :updated_at
6
+
7
+ def initialize(attrs)
8
+ attrs.each do |key, value|
9
+ instance_variable_set("@#{key}", value)
10
+ end
11
+ end
12
+
13
+ def self.all
14
+ apps = get('v1/apps')
15
+ apps.map { |app| new app }
16
+ end
17
+
18
+ def self.find(id)
19
+ app = get("v1/apps/#{id}")
20
+ new app
21
+ end
22
+
23
+ def self.create(opts)
24
+ params = {
25
+ name: opts[:name],
26
+ endpoint: opts[:endpoint]
27
+ }
28
+
29
+ app = post('v1/apps', params)
30
+ new app
31
+ end
32
+
33
+ def save
34
+ params = {
35
+ id: self.id,
36
+ name: self.name,
37
+ endpoint: self.endpoint
38
+ }
39
+
40
+ put("v1/apps/#{self.id}", params)
41
+ self
42
+ end
43
+
44
+ def destroy
45
+ delete("v1/apps/#{self.id}")
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,5 @@
1
+ module Remindrr
2
+ class Configuration
3
+ attr_accessor :client_secret
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ require 'faraday_middleware'
2
+ require 'faraday/raise_http_exception'
3
+
4
+ module Remindrr
5
+ module Connection
6
+ private
7
+
8
+ def connection
9
+ Faraday.new(url: 'http://localhost:3000/api') do |conn|
10
+ conn.headers['Authorization'] = "Token #{Remindrr.config.client_secret}"
11
+ conn.request :url_encoded # form-encode POST params
12
+ conn.response :logger # log requests to STDOUT
13
+ conn.adapter Faraday.default_adapter # make requests with Net::HTTP
14
+ conn.use Faraday::Response::ParseJson
15
+ conn.use FaradayMiddleware::RaiseHttpException
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ module Remindrr
2
+ class Error < StandardError; end
3
+ class Unauthorized < Error; end
4
+ class NotFound < Error; end
5
+ class BadRequest < Error; end
6
+ end
@@ -0,0 +1,36 @@
1
+ module Remindrr
2
+ class Reminder
3
+ extend Request
4
+
5
+ attr_accessor :id, :remind_at, :attempt_count, :data, :created_at
6
+
7
+ def initialize(attrs)
8
+ attrs.each do |key, value|
9
+ instance_variable_set("@#{key}", value)
10
+ end
11
+ end
12
+
13
+ def self.all(app)
14
+ reminders = get("v1/apps/#{app.id}/reminders")
15
+ reminders.map { |reminder| new reminder }
16
+ end
17
+
18
+ def self.find(app, id)
19
+ reminder = get("v1/apps/#{app.id}/reminders/#{id}")
20
+ new reminder
21
+ end
22
+
23
+ def self.create(app, opts)
24
+ reminder = post("v1/apps/#{app.id}/reminders", opts)
25
+ new reminder
26
+ end
27
+
28
+ def self.on(&block)
29
+ @block = block
30
+ end
31
+
32
+ def self.receive(data)
33
+ @block.call(data) unless @block.nil?
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,37 @@
1
+ module Remindrr
2
+ module Request
3
+ include Connection
4
+
5
+ def get(uri)
6
+ connection.get(uri).body
7
+ end
8
+
9
+ def post(url, attributes)
10
+ response = connection.post(url) do |request|
11
+ request.headers['Content-Type'] = 'application/json'
12
+ request.body = attributes.to_json
13
+ end
14
+ response.body.inject({}){ |memo,(k,v)| memo[k.to_sym] = v; memo }
15
+ end
16
+
17
+ def self.extended(base)
18
+ base.include(InstanceMethods)
19
+ end
20
+
21
+ module InstanceMethods
22
+ include Connection
23
+
24
+ def put(url, attributes)
25
+ response = connection.put(url) do |request|
26
+ request.headers['Content-Type'] = 'application/json'
27
+ request.body = attributes.to_json
28
+ end
29
+ response.body.inject({}){ |memo,(k,v)| memo[k.to_sym] = v; memo }
30
+ end
31
+
32
+ def delete(url)
33
+ connection.delete(url)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,41 @@
1
+ require 'json'
2
+
3
+ module Remindrr
4
+ class Server
5
+ def self.call(env)
6
+ new.call(env)
7
+ end
8
+
9
+ def call(env)
10
+ @request = Rack::Request.new(env)
11
+ @response = Rack::Response.new
12
+
13
+ if @request.post?
14
+ receive
15
+ end
16
+
17
+ @response.finish
18
+ end
19
+
20
+ def receive
21
+ body = @request.body.read
22
+ body = parse_request(body)
23
+ Remindrr::Reminder.receive(body)
24
+
25
+ rescue Remindrr::BadRequest => error
26
+ respond_with_error(error)
27
+ end
28
+
29
+ def parse_request(body)
30
+ JSON.parse(body)
31
+ rescue JSON::ParserError
32
+ raise Remindrr::BadRequest, 'Error parsing request body format'
33
+ end
34
+
35
+ def respond_with_error(error)
36
+ @response.status = 400
37
+ @response.write(error.message)
38
+ @response.headers['Content-Type'.freeze] = 'text/plain'.freeze
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,3 @@
1
+ module Remindrr
2
+ VERSION = "0.1.0"
3
+ end
data/remindrr.gemspec ADDED
@@ -0,0 +1,38 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'remindrr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "remindrr"
8
+ spec.version = Remindrr::VERSION
9
+ spec.authors = ["Irakli Lekishvili"]
10
+ spec.email = ["l3kishvili@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby wrapper for remindrr.io API}
13
+ spec.description = %q{A Ruby wrapper for the Remindrr REST API}
14
+ spec.homepage = "http://remindrr.io"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency 'bundler', '~> 1.11'
31
+ spec.add_development_dependency 'rake', '~> 10.0'
32
+ spec.add_development_dependency 'rspec', '~> 3.0'
33
+ spec.add_development_dependency 'vcr', '~> 3.0', '>= 3.0.3'
34
+ spec.add_development_dependency 'webmock', '~> 2.1'
35
+
36
+ spec.add_runtime_dependency 'faraday', '~> 0.9.2'
37
+ spec.add_runtime_dependency 'faraday_middleware', '~> 0.10.0'
38
+ end
metadata ADDED
@@ -0,0 +1,171 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remindrr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Irakli Lekishvili
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.0.3
65
+ type: :development
66
+ prerelease: false
67
+ version_requirements: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - "~>"
70
+ - !ruby/object:Gem::Version
71
+ version: '3.0'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.0.3
75
+ - !ruby/object:Gem::Dependency
76
+ name: webmock
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.1'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '2.1'
89
+ - !ruby/object:Gem::Dependency
90
+ name: faraday
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 0.9.2
96
+ type: :runtime
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.9.2
103
+ - !ruby/object:Gem::Dependency
104
+ name: faraday_middleware
105
+ requirement: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.10.0
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: 0.10.0
117
+ description: A Ruby wrapper for the Remindrr REST API
118
+ email:
119
+ - l3kishvili@gmail.com
120
+ executables: []
121
+ extensions: []
122
+ extra_rdoc_files: []
123
+ files:
124
+ - ".gitignore"
125
+ - ".rspec"
126
+ - ".travis.yml"
127
+ - Gemfile
128
+ - LICENSE.txt
129
+ - README.md
130
+ - Rakefile
131
+ - bin/console
132
+ - bin/setup
133
+ - lib/faraday/raise_http_exception.rb
134
+ - lib/generators/initializer.rb
135
+ - lib/generators/remindrr_generator.rb
136
+ - lib/remindrr.rb
137
+ - lib/remindrr/app.rb
138
+ - lib/remindrr/configuration.rb
139
+ - lib/remindrr/connection.rb
140
+ - lib/remindrr/error.rb
141
+ - lib/remindrr/reminder.rb
142
+ - lib/remindrr/request.rb
143
+ - lib/remindrr/server.rb
144
+ - lib/remindrr/version.rb
145
+ - remindrr.gemspec
146
+ homepage: http://remindrr.io
147
+ licenses:
148
+ - MIT
149
+ metadata:
150
+ allowed_push_host: https://rubygems.org
151
+ post_install_message:
152
+ rdoc_options: []
153
+ require_paths:
154
+ - lib
155
+ required_ruby_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ required_rubygems_version: !ruby/object:Gem::Requirement
161
+ requirements:
162
+ - - ">="
163
+ - !ruby/object:Gem::Version
164
+ version: '0'
165
+ requirements: []
166
+ rubyforge_project:
167
+ rubygems_version: 2.5.1
168
+ signing_key:
169
+ specification_version: 4
170
+ summary: Ruby wrapper for remindrr.io API
171
+ test_files: []