firebased 0.1.0

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: c6d2d4e39a94908550d701dbc25fd3535e7ed974
4
+ data.tar.gz: 99de4196b9c662b96fd7f4f7d4b360478d3cd740
5
+ SHA512:
6
+ metadata.gz: 519486eb946105c80c93562209279c739e41d3c2b2dd036c2efe3582c0b4e6da48c7ecb7434cfd63c7cf64528d04043fe948cf6e4cbec889cc19aa0f43ae8627
7
+ data.tar.gz: 30b1dca9ccad1b2f42f89a7fd8bd55c235b27a1b4210e89aeeac8e4b1f5de4f1b3e4c5959850e4954ff62834538570bdadc854b20f335f8b80e6fd0acef27caa
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 firebased.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Miles Zimmerman
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,64 @@
1
+ # Firebased
2
+
3
+ A ruby gem to deploy and manage Firebase instances programaticaly. Based off of [firebase-admin](https://github.com/casetext/firebase-admin) by [casetext](https://github.com/casetext).
4
+
5
+ Only create/get/delete implemented, will do more when time/necesity demands it (or a blessed soul submits a pull request).
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'firebased'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install firebased
22
+
23
+
24
+ ## Configure
25
+
26
+ First, put your Firebase account email and password in some environment files.
27
+
28
+ Then either in an initializer if on rails, or wherever else, include a config block:
29
+
30
+ ```ruby
31
+ Firebased.configure do |config|
32
+ config.email = ENV['FIREBASE_EMAIL']
33
+ config.password = ENV['FIREBASE_PASS']
34
+ end
35
+ ```
36
+
37
+
38
+ ## Usage
39
+
40
+ #### Create a Firebase
41
+
42
+ ```ruby
43
+ fb = Firebased.create_firebase('my-firebase-url-slug', 'My Optional Firebase Name')
44
+ ```
45
+
46
+ #### Retrieve a Firebase
47
+
48
+ ```ruby
49
+ fb = Firebased.get_firebase('my-firebase-url-slug')
50
+ ```
51
+
52
+ #### Delete a Firebase
53
+
54
+ ```ruby
55
+ Firebased.delete_firebase('my-firebase-url-slug')
56
+ ```
57
+
58
+ ## Contributing
59
+
60
+ 1. Fork it ( https://github.com/econlab/firebased/fork )
61
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
62
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
63
+ 4. Push to the branch (`git push origin my-new-feature`)
64
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/firebased.gemspec ADDED
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'firebased/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "firebased"
8
+ spec.version = Firebased::VERSION
9
+ spec.authors = ["Miles Zimmerman"]
10
+ spec.email = ["miles@maztek.io"]
11
+ spec.summary = %q{Deploy and manage Firebase instances programatically}
12
+ spec.description = %q{A ruby gem to deploy and manage Firebase instances programaticaly. Based off of firebase-admin by casetext.}
13
+ spec.homepage = "https://github.com/econlab/firebased"
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_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "minitest"
24
+ spec.add_development_dependency "vcr"
25
+ spec.add_development_dependency "webmock"
26
+
27
+ spec.add_dependency "faraday"
28
+ spec.add_dependency "json"
29
+ end
data/lib/firebased.rb ADDED
@@ -0,0 +1,39 @@
1
+ require_relative 'firebased/version'
2
+
3
+ require_relative 'firebased/account'
4
+ require_relative 'firebased/firebase'
5
+ require_relative 'firebased/configurable'
6
+
7
+ module Firebased
8
+ class << self
9
+ include Firebased::Configurable
10
+
11
+ # Delegate to a Firebased::Account
12
+ #
13
+ # @return [Firebased::Account]
14
+ def client
15
+ @client = Firebased::Account.new(credentials) unless defined?(@client)
16
+ @client
17
+ end
18
+
19
+ # Has a client been initialized on the Firebased module?
20
+ #
21
+ # @return [Boolean]
22
+ def client?
23
+ !!@client
24
+ end
25
+
26
+
27
+ def respond_to?(method_name, include_private=false)
28
+ client.respond_to?(method_name, include_private) || super
29
+ end
30
+
31
+ private
32
+
33
+ def method_missing(method_name, *args, &block)
34
+ return super unless client.respond_to?(method_name)
35
+ client.send(method_name, *args, &block)
36
+ end
37
+
38
+ end
39
+ end
@@ -0,0 +1,69 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ ACCOUNT_BASE = 'https://admin.firebase.com/account'
5
+ FIRE_BASE = 'https://admin.firebase.com/firebase'
6
+
7
+ module Firebased
8
+ class Account
9
+ attr_reader :email, :pass, :token, :bases
10
+
11
+ def initialize(email, pass, token = nil)
12
+ @email = email
13
+ @pass = pass
14
+ @token = token
15
+ @bases = {}
16
+ login! unless token
17
+ end
18
+
19
+
20
+ # Fetches admin token if not passed on initialize
21
+ def login!
22
+ params = { email: email, password: pass }
23
+ response = Faraday.get("#{ACCOUNT_BASE}/login", params)
24
+ attributes = JSON.parse(response.body)
25
+ @token = attributes["adminToken"]
26
+ end
27
+
28
+
29
+ # Create a new firebase
30
+ #
31
+ # @param name [String] slug/url-friendly app name
32
+ # @param app_name [String] title of firebase
33
+ #
34
+ # @return [Firebased::Firebase] a fresh new Firebase instance
35
+ def create_firebase(name, app_name = nil)
36
+ params = { token: @token, appName: app_name || name }
37
+ response = Faraday.post("#{FIRE_BASE}/#{name}", params)
38
+ response = JSON.parse(response.body)
39
+ firebase = Firebased::Firebase.new(name, @token) if response["success"]
40
+ @bases[name] = firebase
41
+ return firebase
42
+ end
43
+
44
+
45
+ # Fetch an existing firebase
46
+ #
47
+ # @param name [String] slug/url-friendly app name
48
+ #
49
+ # @return [Firebased::Firebase] a fresh new Firebase instance
50
+ def get_firebase(name)
51
+ @bases[name] || Firebased::Firebase.new(name, @token)
52
+ end
53
+
54
+
55
+ # Delete an existing firebase
56
+ #
57
+ # @param name [String] slug/url-friendly app name
58
+ #
59
+ # @return [Firebased::Firebase] a fresh new Firebase instance
60
+ def delete_firebase(name)
61
+ params = { "_method" => "DELETE", namespace: name, token: @token }
62
+ response = Faraday.post("#{FIRE_BASE}/#{name}", params)
63
+ response = JSON.parse(response.body)
64
+ p response["error"]
65
+ @bases.delete(name) unless response["error"]
66
+ end
67
+
68
+ end
69
+ end
@@ -0,0 +1,29 @@
1
+ module Firebased
2
+ module Configurable
3
+ attr_writer :email, :password
4
+
5
+ class << self
6
+ def keys
7
+ @keys ||= [:email, :password, :token]
8
+ end
9
+ end
10
+
11
+ # Allow block configuration
12
+ def configure
13
+ yield self
14
+ self
15
+ end
16
+
17
+ private
18
+
19
+ # @return [Hash]
20
+ def credentials
21
+ {
22
+ email: @email,
23
+ password: @password,
24
+ token: @token
25
+ }
26
+ end
27
+
28
+ end
29
+ end
@@ -0,0 +1,33 @@
1
+ require 'faraday'
2
+ require 'json'
3
+
4
+ FIRE_BASE = 'https://admin.firebase.com/firebase'
5
+
6
+ module Firebased
7
+ class Firebase
8
+ attr_accessor :name, :personal_token, :admin_token, :firebase_token, :auth_tokens
9
+
10
+ def initialize(name, admin_token)
11
+ @name = name
12
+ @admin_token = admin_token
13
+ generate_reference!
14
+ end
15
+
16
+
17
+ def auth_tokens
18
+ return @auth_tokens || get_auth_tokens
19
+ end
20
+
21
+
22
+ private
23
+
24
+ def generate_reference!
25
+ params = { token: @admin_token, namespace: @name }
26
+ response = Faraday.get("#{FIRE_BASE}/#{name}/token", params)
27
+ attributes = JSON.parse(response.body)
28
+ @personal_token = attributes["personalToken"]
29
+ @firebase_token = attributes["firebaseToken"]
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,3 @@
1
+ module Firebased
2
+ VERSION = "0.1.0"
3
+ end
data/test/.DS_Store ADDED
Binary file
Binary file
@@ -0,0 +1,18 @@
1
+ require './test/test_helper'
2
+
3
+ class FirebasedAccountTest < Minitest::Test
4
+
5
+ def test_exists
6
+ assert Firebased::Account
7
+ end
8
+
9
+ def test_account_logs_in_when_token_omitted
10
+ VCR.use_cassette('account', :record => :once) do
11
+ account = Firebased::Account.new('email', 'pass')
12
+
13
+ assert_equal Firebased::Account, account.class
14
+ refute_nil account.token
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,33 @@
1
+ require 'securerandom'
2
+ require './test/test_helper'
3
+
4
+ class FirebasedAccountTest < Minitest::Test
5
+
6
+ def setup
7
+ @account = Firebased::Account.new('email', 'pass', 'token')
8
+ @hash = SecureRandom.hex.to_s
9
+ end
10
+
11
+ def test_can_create_firebase
12
+ p @hash
13
+ VCR.use_cassette('firebase_created', :record => :all) do
14
+ fb = @account.create_firebase(@hash)
15
+ refute_nil fb
16
+ end
17
+ end
18
+
19
+ def test_can_get_firebase
20
+ p @hash
21
+ fb = @account.get_firebase(@hash)
22
+ refute_nil fb
23
+ end
24
+
25
+ def test_can_delete_firebase
26
+ p @hash
27
+ VCR.use_cassette('firebase_deleted', :record => :all) do
28
+ fb = @account.delete_firebase(@hash)
29
+ assert_nil @account.bases[@hash]
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,9 @@
1
+ require './lib/firebased'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+ require 'vcr'
5
+
6
+ VCR.configure do |c|
7
+ c.cassette_library_dir = "test/fixtures"
8
+ c.hook_into :webmock
9
+ end
metadata ADDED
@@ -0,0 +1,164 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: firebased
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Miles Zimmerman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-16 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
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: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
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: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: json
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: A ruby gem to deploy and manage Firebase instances programaticaly. Based
112
+ off of firebase-admin by casetext.
113
+ email:
114
+ - miles@maztek.io
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - firebased.gemspec
125
+ - lib/firebased.rb
126
+ - lib/firebased/account.rb
127
+ - lib/firebased/configurable.rb
128
+ - lib/firebased/firebase.rb
129
+ - lib/firebased/version.rb
130
+ - test/.DS_Store
131
+ - test/account/.DS_Store
132
+ - test/account/account_test.rb
133
+ - test/account/firebase_test.rb
134
+ - test/test_helper.rb
135
+ homepage: https://github.com/econlab/firebased
136
+ licenses:
137
+ - MIT
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.2.2
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Deploy and manage Firebase instances programatically
159
+ test_files:
160
+ - test/.DS_Store
161
+ - test/account/.DS_Store
162
+ - test/account/account_test.rb
163
+ - test/account/firebase_test.rb
164
+ - test/test_helper.rb