cangaroo_endpoint_base 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: 7ecc8e671ea559bacd80dcd6f9443cfb0745979a
4
+ data.tar.gz: ab1de70e27da70953e0d837a5758ddef1392b774
5
+ SHA512:
6
+ metadata.gz: 10fdab2caafb5e536c246d5ee4bec3eb81e4919787c288353980f2df7bef6e02088b0f9b6811114355e0b9d46bebfb4b3d1b77b1e57f910570021e6e4a0b041d
7
+ data.tar.gz: 2d414757b42ce4a0b5d5b739b9b19c75f70971fa87cc9441e321a24f0d1c797f9f16a0b75344b525b3b7c853c100990c6d9c1fb0eab7585611e802d4d1335d8d
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'rails', '>= 5.0.0'
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # CangarooEndpointBase
2
+
3
+ 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/cangaroo_endpoint_base`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'cangaroo_endpoint_base'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install cangaroo_endpoint_base
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/cangaroo_endpoint_base.
36
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "cangaroo_endpoint_base"
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,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cangaroo_endpoint_base/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "cangaroo_endpoint_base"
8
+ spec.version = CangarooEndpointBase::VERSION
9
+ spec.authors = ["Michael Bianco"]
10
+ spec.email = ["mike@cliffsidemedia.com"]
11
+
12
+ spec.summary = 'Helpers for developing a Cangaroo (Wombat replacement) endpoint'
13
+ spec.homepage = 'https://github.com/iloveitaly/cangaroo_endpoint_base'
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'simple_structured_logger'
21
+ spec.add_dependency 'rails'
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.12"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest", "~> 5.0"
26
+ end
@@ -0,0 +1,45 @@
1
+ module CangarooEndpointBase
2
+ module ApplicationControllerHelper
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include SimpleStructuredLogger
7
+ include ActionController::HttpAuthentication::Basic::ControllerMethods
8
+
9
+ http_basic_authenticate_with(
10
+ name: '',
11
+ password: ENV['ENDPOINT_BASIC_AUTH_TOKEN']
12
+ )
13
+
14
+ before_action :reset_context
15
+
16
+ rescue_from StandardError do |exception|
17
+ Rollbar.error(exception) if defined?(::Rollbar)
18
+
19
+ render json: { :error => exception.message }, status: :internal_server_error
20
+ end if !Rails.env.test?
21
+ end
22
+
23
+ protected
24
+
25
+ def reset_context
26
+ log.reset_context!
27
+ end
28
+
29
+ def last_poll_from_params
30
+ last_poll = Time.at(params[:last_poll].to_i).to_datetime rescue nil
31
+
32
+ if last_poll.nil?
33
+ render json: "no last poll specified", status: :bad_request
34
+ return
35
+ end
36
+
37
+ if Rails.env.production? && last_poll < 2.week.ago
38
+ render json: "last poll should never be more than two weeks in the past", status: :bad_request
39
+ return
40
+ end
41
+
42
+ last_poll
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,27 @@
1
+ module CangarooEndpointBase
2
+ module SpecHelper
3
+ def setup_http_basic_auth
4
+ request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic
5
+ .encode_credentials('', ENV['ENDPOINT_BASIC_AUTH_TOKEN'])
6
+
7
+ # force JSON type so ruby hash => json string on post/patch/etc
8
+ request.env['CONTENT_TYPE'] = 'application/json'
9
+ end
10
+
11
+ def parsed_response(parse = false)
12
+ if @parsed_response.blank? || parse
13
+ @parsed_response = JSON.parse(response.body)
14
+ end
15
+
16
+ @parsed_response
17
+ end
18
+
19
+ def read_fixture(name)
20
+ JSON.parse(File.read(File.join(Rails.root, "spec/support/fixtures/#{name}.json")))
21
+ end
22
+ end
23
+ end
24
+
25
+ RSpec.configure do |config|
26
+ config.include CangarooEndpointBase::SpecHelper, type: :controller
27
+ end
@@ -0,0 +1,3 @@
1
+ module CangarooEndpointBase
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,8 @@
1
+ require "cangaroo_endpoint_base/version"
2
+ require 'cangaroo_endpoint_base/application_controller_helper'
3
+
4
+ require 'simple_structured_logger'
5
+
6
+ module CangarooEndpointBase
7
+
8
+ end
metadata ADDED
@@ -0,0 +1,124 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cangaroo_endpoint_base
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Michael Bianco
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-08-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: simple_structured_logger
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rails
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: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.12'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.12'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description:
84
+ email:
85
+ - mike@cliffsidemedia.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - Gemfile
92
+ - README.md
93
+ - Rakefile
94
+ - bin/console
95
+ - bin/setup
96
+ - cangaroo_endpoint_base.gemspec
97
+ - lib/cangaroo_endpoint_base.rb
98
+ - lib/cangaroo_endpoint_base/application_controller_helper.rb
99
+ - lib/cangaroo_endpoint_base/spec/spec_helper.rb
100
+ - lib/cangaroo_endpoint_base/version.rb
101
+ homepage: https://github.com/iloveitaly/cangaroo_endpoint_base
102
+ licenses: []
103
+ metadata: {}
104
+ post_install_message:
105
+ rdoc_options: []
106
+ require_paths:
107
+ - lib
108
+ required_ruby_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ requirements: []
119
+ rubyforge_project:
120
+ rubygems_version: 2.6.4
121
+ signing_key:
122
+ specification_version: 4
123
+ summary: Helpers for developing a Cangaroo (Wombat replacement) endpoint
124
+ test_files: []