globber 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ad8798599cf2cb6067dcc4494aef52bad7fa22fe
4
+ data.tar.gz: f843359e717f14ef4f2b9bb891f4a2762bf1da41
5
+ SHA512:
6
+ metadata.gz: 482ff8b34a237a7ce45985aa51d19293bc9928f6b6e0ac1f1b364fd12fb291c0e1a24af8e78a95c8a0ac4398a9073b0e41a7190bb6587d72eb32773f4d283ff7
7
+ data.tar.gz: a4536029d6c1a6fa6eedbde999b4c504f9fa1a1ce986a550096d7bf9eb49d883ee9d66d843d21594bf597b7b7787a036ff9cd8bee28f62d8a8dae1ed4f247ba3
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Jake Peterson
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.rdoc ADDED
@@ -0,0 +1,24 @@
1
+ # Globber
2
+ Utilize the ruby on rails environment backed by any api server!
3
+
4
+ ## Installation
5
+ In your `Gemfile`:
6
+ ```ruby
7
+ gem 'globber'
8
+ ```
9
+ In `config/routes.rb`:
10
+ ```ruby
11
+ mount Globber::Engine => "/"
12
+ ```
13
+ In `config/initializers/globber.rb`:
14
+ ```ruby
15
+ Globber.configure do |c|
16
+ c.base_uri = 'http://api.yoursite.com'
17
+ end
18
+ ```
19
+ ##### Now whichever route is passed to rails will be mapped to your API server.
20
+ __E.g.__ http://localhost:3000/1/caliber/popular Becomes http://api.yoursite.com/1/caliber/popular
21
+ And you receive your JSON data server-side.
22
+
23
+ ## Author
24
+ [@jakenberg](https://github.com/jakenberg)
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Globber'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,10 @@
1
+ module Globber
2
+ class ApplicationController < ActionController::Base
3
+
4
+ def index
5
+ @result = RouterService.call(params)
6
+ render json: @result.display
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ module Globber
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ class Remote
2
+ include HTTParty
3
+ base_uri Globber.configuration.base_uri
4
+
5
+ headers({
6
+ "Content-Type" => 'application/json; charset=utf-8;',
7
+ "Accept" => "application/json"
8
+ })
9
+
10
+ def self.get(path)
11
+ super "/#{path}"
12
+ end
13
+
14
+ end
@@ -0,0 +1,24 @@
1
+ # Hat tip https://netguru.co/blog/service-objects-in-rails-will-help
2
+ class Error
3
+ attr_reader :errors
4
+ # Pass 1 string or array of strings
5
+ def initialize(errors = nil)
6
+ errors = [] unless errors
7
+ @errors = [errors].flatten # handle array or string
8
+ end
9
+
10
+ def error_message
11
+ error[0]
12
+ end
13
+
14
+ def success?
15
+ false
16
+ end
17
+
18
+ def display
19
+ return {
20
+ success: false,
21
+ errors: @errors
22
+ }
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ require 'httparty'
2
+ require 'virtus'
3
+
4
+ class RouterService
5
+ include Service
6
+ include Virtus.model(:strict => true)
7
+
8
+ attribute :route, String
9
+
10
+ def call
11
+ response = Remote.get(route)
12
+ unless response.body.length == 0
13
+ return Success.new(response: response)
14
+ else
15
+ return Error.new([
16
+ {
17
+ status: response.code,
18
+ message: response.message
19
+ }
20
+ ])
21
+ end
22
+ end
23
+
24
+ end
@@ -0,0 +1,10 @@
1
+ # Hat tip http://brewhouse.io/blog/2014/04/30/gourmet-service-objects.html
2
+ module Service
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ def self.call(*args)
7
+ new(*args).call
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,15 @@
1
+ # Hat tip https://netguru.co/blog/service-objects-in-rails-will-help
2
+ class Success
3
+ attr_reader :data
4
+ def initialize(data)
5
+ @data = data
6
+ end
7
+
8
+ def success?
9
+ true
10
+ end
11
+
12
+ def display
13
+ @data
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Globber</title>
5
+ <%= stylesheet_link_tag "globber/application", media: "all" %>
6
+ <%= javascript_include_tag "globber/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ Globber::Engine.routes.draw do
2
+ get '*route', to: 'application#index'
3
+ end
data/lib/globber.rb ADDED
@@ -0,0 +1,15 @@
1
+ require "globber/engine"
2
+
3
+ module Globber
4
+ class << self
5
+ attr_writer :configuration
6
+ end
7
+
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def self.configure
13
+ yield(configuration)
14
+ end
15
+ end
@@ -0,0 +1,5 @@
1
+ module Globber
2
+ class Configuration
3
+ attr_accessor :base_uri
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ require 'rails/all'
2
+
3
+ require 'globber/version'
4
+ require 'globber/configuration'
5
+
6
+ module Globber
7
+ class Engine < ::Rails::Engine
8
+ isolate_namespace Globber
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Globber
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :globber do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: globber
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jake Peterson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.2.3
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.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: virtus
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: httparty
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
+ description: ''
56
+ email:
57
+ - jsksma2@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.rdoc
64
+ - Rakefile
65
+ - app/assets/javascripts/globber/application.js
66
+ - app/assets/stylesheets/globber/application.css
67
+ - app/controllers/globber/application_controller.rb
68
+ - app/helpers/globber/application_helper.rb
69
+ - app/models/remote.rb
70
+ - app/services/error.rb
71
+ - app/services/router_service.rb
72
+ - app/services/service.rb
73
+ - app/services/success.rb
74
+ - app/views/layouts/globber/application.html.erb
75
+ - config/routes.rb
76
+ - lib/globber.rb
77
+ - lib/globber/configuration.rb
78
+ - lib/globber/engine.rb
79
+ - lib/globber/version.rb
80
+ - lib/tasks/globber_tasks.rake
81
+ homepage: https://github.com/jakenberg
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.4.8
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Utilize the ruby on rails environment backed by any api server!
105
+ test_files: []