glassfrog 0.3.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: c89ef4ee91bbf6648c716f375c63c4bc1e6cb124
4
+ data.tar.gz: 4c4d158ce34299e65c377c53fe598f4bbab85097
5
+ SHA512:
6
+ metadata.gz: 23762758ceba1cb5f9860e7a487b9b554fbc72f3997d562e91a661cba4d637e8c2007ffd3defb3d60dd5533a4dfa6d78a75728f92313ace19811dc666e6e4de1
7
+ data.tar.gz: 121c1061db9c5c11a55a428baf46305015d19b3dd7f56284157dda098c2e418b430d24010393960053ad946dae0e0e22a9bcd65829dd93756d49680d24558430
data/.gitignore ADDED
@@ -0,0 +1,74 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /var/
11
+
12
+ # OS X
13
+ .DS_Store
14
+ .AppleDouble
15
+ .LSOverride
16
+
17
+ # Icon must end with two \r
18
+ Icon
19
+
20
+
21
+ # Thumbnails
22
+ ._*
23
+
24
+ # Files that might appear in the root of a volume
25
+ .DocumentRevisions-V100
26
+ .fseventsd
27
+ .Spotlight-V100
28
+ .TemporaryItems
29
+ .Trashes
30
+ .VolumeIcon.icns
31
+
32
+ # Directories potentially created on remote AFP share
33
+ .AppleDB
34
+ .AppleDesktop
35
+ Network Trash Folder
36
+ Temporary Items
37
+ .apdisk
38
+
39
+ # Ruby
40
+ *.gem
41
+ *.rbc
42
+ /.config
43
+ /coverage/
44
+ /InstalledFiles
45
+ /pkg/
46
+ /spec/reports/
47
+ /test/tmp/
48
+ /test/version_tmp/
49
+ /tmp/
50
+
51
+ ## Specific to RubyMotion:
52
+ .dat*
53
+ .repl_history
54
+ build/
55
+
56
+ ## Documentation cache and generated files:
57
+ /.yardoc/
58
+ /_yardoc/
59
+ /doc/
60
+ /rdoc/
61
+
62
+ ## Environment normalisation:
63
+ /.bundle/
64
+ /vendor/bundle
65
+ /lib/bundler/man/
66
+
67
+ # for a library or gem, you might want to ignore these files since the code is
68
+ # intended to run in multiple environments; otherwise, check them in:
69
+ # Gemfile.lock
70
+ # .ruby-version
71
+ # .ruby-gemset
72
+
73
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
74
+ .rvmrc
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.0.0
4
+ before_install: gem install bundler -v 1.10.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in glassfrog.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Undercurrent
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,198 @@
1
+ # Glassfrog
2
+
3
+ A Ruby interface for the GlassFrog API.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'glassfrog'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install glassfrog
20
+
21
+ ## Documentation
22
+
23
+ To generate local rdocs run:
24
+
25
+ $ rdoc
26
+
27
+ ## Configuration
28
+
29
+ The GlassFrog API requires a personally generated GlassFrog API key.
30
+
31
+ This can be passed into `Glassfrog::Client.new` as a String, Hash, or a Block.
32
+
33
+ ```ruby
34
+ client = Glassfrog::Client.new("YOUR_API_KEY")
35
+ ```
36
+
37
+ ```ruby
38
+ client = Glassfrog::Client.new({
39
+ api_key: "YOUR_API_KEY"
40
+ })
41
+ ```
42
+
43
+ ```ruby
44
+ client = Glassfrog::Client.new do |config|
45
+ config.api_key = "YOUR_API_KEY"
46
+ end
47
+ ```
48
+
49
+ ## Usage
50
+
51
+ This GlassFrog interface also has a caching feature which allows https requests to be cached and only sent once.
52
+
53
+ To set caching with the default (temporary) cache, pass `true` to the `caching` variable.
54
+
55
+ ```ruby
56
+ client = Glassfrog::Client.new({
57
+ api_key: "YOUR_API_KEY",
58
+ caching: true
59
+ })
60
+ ```
61
+
62
+ ```ruby
63
+ client = Glassfrog::Client.new do |config|
64
+ config.api_key = "YOUR_API_KEY"
65
+ config.caching = true
66
+ end
67
+ ```
68
+
69
+ You can change the location of the cache file (or storage type) by passing in a `caching_settings` Hash.
70
+
71
+ ```ruby
72
+ client = Glassfrog::Client.new({
73
+ api_key: "YOUR_API_KEY",
74
+ caching: true,
75
+ caching_settings: {
76
+ :metastore => 'file:/var/cache/rack/meta',
77
+ :entitystore => 'file:/var/cache/rack/body'
78
+ }
79
+ })
80
+ ```
81
+
82
+ ```ruby
83
+ client = Glassfrog::Client.new do |config|
84
+ config.api_key = "YOUR_API_KEY"
85
+ config.caching = true
86
+ caching_settings: {
87
+ :metastore => 'file:/var/cache/rack/meta',
88
+ :entitystore => 'file:/var/cache/rack/body'
89
+ }
90
+ end
91
+ ```
92
+
93
+ ### Once the client has been configured:
94
+
95
+ #### GET all circles (or other objects)
96
+
97
+ ```ruby
98
+ circles = client.get :circles
99
+ roles = client.get :roles
100
+ ```
101
+
102
+ #### GET a specific circle (or other object) with an ID
103
+
104
+ ```ruby
105
+ circle_1 = client.get :circle, 1
106
+ role_1 = client.get :role, 1
107
+ ```
108
+
109
+ #### GET a specific circle (or other object) with an object with an ID
110
+
111
+ ```ruby
112
+ circle_1 = client.get :circle, Glassfrog::Circle.new({ id: 1 })
113
+ role_1 = client.get :role, Glassfrog::Role.new({ id: 1 })
114
+ ```
115
+
116
+ ##### Note: Updating certain objects require specific keys (people requires admin access)
117
+
118
+ #### Create a checklist item, metric, person, or project with POST and an object
119
+
120
+ ```ruby
121
+ new_person = client.post :person, Glassfrog::Person.new({
122
+ name: 'Jim Bob',
123
+ email: 'jim.bob@example.org'
124
+ })
125
+ ```
126
+
127
+ #### Create a checklist item, metric, person, or project with POST and a Hash
128
+
129
+ ```ruby
130
+ new_person = client.post :person, {
131
+ name: 'Jim Bob',
132
+ email: 'jim.bob@example.org'
133
+ }
134
+ ```
135
+
136
+ #### Update a checklist item, metric, person, or project with PATCH and an object (returns update object)
137
+
138
+ ```ruby
139
+ updated_person = client.patch :person, Glassfrog::Person.new({
140
+ id: 1,
141
+ email: 'jb@newemail.org'
142
+ })
143
+ ```
144
+
145
+ #### Update a checklist item, metric, person, or project with PATCH and a Hash (returns update options)
146
+
147
+ ```ruby
148
+ updated_person = client.patch :person, {
149
+ id: 1
150
+ email: 'jb@newemail.org'
151
+ })
152
+ ```
153
+
154
+ #### Update a checklist item, metric, person, or project with PATCH, a Hash (or an object), and a supplied identifier (returns update options)
155
+
156
+ ```ruby
157
+ updated_person = client.patch :person, 1, {
158
+ email: 'jb@newemail.org'
159
+ })
160
+ ```
161
+
162
+ #### Delete a checklist item, metric, person, or project with DELETE and an object (returns boolean)
163
+
164
+ ```ruby
165
+ was_deleted = client.patch :person, {
166
+ id: 1
167
+ email: 'jb@newemail.org'
168
+ })
169
+ ```
170
+
171
+ #### Delete a checklist item, metric, person, or projectw with DELETE and an identifier (returns boolean)
172
+
173
+ ```ruby
174
+ was_deleted = client.patch :person, 1
175
+ ```
176
+
177
+ #### Build a hierarchy from an array of circles and roles, or get them from GlassFrog
178
+
179
+ ```ruby
180
+ root_circle = client.build_hierarchy circles, roles
181
+ root_circle_from_get = client.build_hierarchy
182
+ ```
183
+
184
+ ## Development
185
+
186
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
187
+
188
+ 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).
189
+
190
+ ## Contributing
191
+
192
+ Bug reports and pull requests are welcome on GitHub at https://github.com/UCSoftware/glassfrog.
193
+
194
+
195
+ ## License
196
+
197
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
198
+
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 "glassfrog"
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,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/glassfrog.gemspec ADDED
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'glassfrog/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "glassfrog"
8
+ spec.version = Glassfrog::VERSION
9
+ spec.authors = ["Undercurrent"]
10
+ spec.email = ["robert.wells@undercurrent.com"]
11
+
12
+ spec.summary = %q{A Ruby interface for the GlassFrog API.}
13
+ spec.homepage = "https://github.com/UCSoftware/glassfrog-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ # Runtime Dependencies
22
+ spec.add_runtime_dependency "addressable"
23
+ spec.add_runtime_dependency "http"
24
+ spec.add_runtime_dependency "rack-cache"
25
+
26
+ # Development Dependencies
27
+ spec.add_development_dependency "bundler", "~> 1.10"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec"
30
+ end
@@ -0,0 +1,29 @@
1
+ require 'glassfrog/base'
2
+ require 'glassfrog/rest/get'
3
+
4
+ module Glassfrog
5
+ #
6
+ # Encapsulates GlassFrog Actions.
7
+ #
8
+ class Action < Glassfrog::Base
9
+ # @return [String]
10
+ attr_accessor :description, :created_at
11
+ # @return [Boolean]
12
+ attr_accessor :private_to_circle
13
+ # @return [Hash]
14
+ attr_accessor :links
15
+ PATH = '/actions'
16
+ TYPE = :actions
17
+
18
+ #
19
+ # Sends a GET request for Action(s) to GlassFrog.
20
+ # @param client [Glassfrog::Client] The client that will send the request. Contains the API key.
21
+ # @param options [Hash, Glassfrog::Base] The options used to find the correct Actions(s).
22
+ #
23
+ # @return [Array<Glassfrog::Action>] The array of Action(s) fetched from GlassFrog.
24
+ def self.get(client, options)
25
+ response = Glassfrog::REST::Get.irregular_get(client, TYPE, PATH, options)
26
+ response[TYPE] ? response[TYPE].map { |object| self.new(object) } : []
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,43 @@
1
+ require 'glassfrog/utils/utils'
2
+
3
+ module Glassfrog
4
+ #
5
+ # Superclass of all GlassFrog classes.
6
+ #
7
+ class Base
8
+ include Glassfrog::Utils
9
+ # @return [Integer]
10
+ attr_accessor :id
11
+
12
+ #
13
+ # Initializes a new Base object.
14
+ # @param attrs = {} [Hash] Attributes used to instantiate Base object.
15
+ #
16
+ # @return [Glassfrog::Base] The new Base object.
17
+ def initialize(attrs = {})
18
+ attrs.each do |key, value|
19
+ instance_variable_set("@#{key}", value);
20
+ end
21
+ yield(self) if block_given?
22
+ end
23
+
24
+ #
25
+ # Check equality between two objects. Should be equal if they are the same type and their IDs are also equal.
26
+ # @param other [Glassfrog::Base] The object to compare to self.
27
+ #
28
+ # @return [Boolean] They are equal or not.
29
+ def ==(other)
30
+ self.id == other.id && self.class == other.class
31
+ end
32
+
33
+ #
34
+ # Turns the Base object into a hash.
35
+ #
36
+ # @return [Hash] Hash version of the Base object.
37
+ def hashify
38
+ hash = Hash.new
39
+ self.instance_variables.each { |var| hash[var.to_s.delete("@")] = self.instance_variable_get(var) }
40
+ symbolize_keys(hash)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,89 @@
1
+ require 'glassfrog/base'
2
+ require 'glassfrog/rest/get'
3
+ require 'glassfrog/rest/post'
4
+ require 'glassfrog/rest/patch'
5
+ require 'glassfrog/rest/delete'
6
+
7
+ module Glassfrog
8
+ #
9
+ # Encapsulates GlassFrog Checklist Items.
10
+ #
11
+ class ChecklistItem < Glassfrog::Base
12
+ # @return [String]
13
+ attr_accessor :description, :frequency
14
+ # @return [Boolean]
15
+ attr_accessor :global
16
+ # @return [Hash]
17
+ attr_accessor :links
18
+ PATH = '/checklist_items'
19
+ TYPE = :checklist_items
20
+
21
+ #
22
+ # Sends a GET request for ChecklistItem(s) to GlassFrog.
23
+ # @param client [Glassfrog::Client] The client that will send the request. Contains the API key.
24
+ # @param options [Hash, Glassfrog::Base] The options used to find the correct ChecklistItems(s).
25
+ #
26
+ # @return [Array<Glassfrog::ChecklistItem>] The array of ChecklistItem(s) fetched from GlassFrog.
27
+ def self.get(client, options)
28
+ response = Glassfrog::REST::Get.irregular_get(client, TYPE, PATH, options)
29
+ response[TYPE] ? response[TYPE].map { |object| self.new(object) } : []
30
+ end
31
+
32
+ #
33
+ # Sends a POST request to create a ChecklistItem on GlassFrog.
34
+ # @param client [Glassforg::Client] The client that will send the request. Contains the API key.
35
+ # @param options [Hash, Glassforg::Base] The options used to create the new ChecklistItems.
36
+ #
37
+ # @return [Array<Glassfrog::ChecklistItem>] The array containing the new ChecklistItem.
38
+ def self.post(client, options)
39
+ response = Glassfrog::REST::Post.post(client, PATH, { TYPE => [parse_options(options)] })
40
+ response[TYPE] ? response[TYPE].map { |object| self.new(object) } : []
41
+ end
42
+
43
+ #
44
+ # Sends a PATCH request to update a ChecklistItem on GlassFrog.
45
+ # @param client [Glassforg::Client] The client that will send the request. Contains the API key.
46
+ # @param identifier [Integer] The ID of the ChecklistItem to be updated.
47
+ # @param options [Hash, Glassfrog::Base] The options used to update the ChecklistItem.
48
+ #
49
+ # @return [Boolean] Whether the request failed or not.
50
+ def self.patch(client, identifier, options)
51
+ options = Glassfrog::REST::Patch.formify(parse_options(options), self)
52
+ response = Glassfrog::REST::Patch.patch(client, PATH + '/' + identifier.to_s, options)
53
+ end
54
+
55
+ #
56
+ # Sends a DELETE request to delete a ChecklistItem on GlassFrog.
57
+ # @param client [Glassforg::Client] The client that will send the request. Contains the API key.
58
+ # @param options [Hash, Glassfrog::Base] The options containing the ID of the ChecklistItem to delete.
59
+ #
60
+ # @return [Boolean] Whether the request failed or not.
61
+ def self.delete(client, options)
62
+ path = PATH + '/' + options.delete(:id).to_s
63
+ response = Glassfrog::REST::Delete.delete(client, path, options)
64
+ end
65
+
66
+ private
67
+
68
+ PARAMS = [
69
+ :description,
70
+ :frequency,
71
+ :global,
72
+ :circle_id,
73
+ :role_id
74
+ ]
75
+
76
+ #
77
+ # Grabs only the parameters accepted by GlassFrog.
78
+ # @param options [Hash] Inputed options.
79
+ #
80
+ # @return [Hash] Valid GlassFrog options.
81
+ def self.parse_options(options)
82
+ options[:circle_id] = options[:links][:circle] if options[:links] && options[:links][:circle]
83
+ options[:role_id] = options[:links][:role] if options[:links] && options[:links][:role]
84
+ params_hash = Hash.new
85
+ PARAMS.each { |param| params_hash[param] = options[param] if options[param] }
86
+ params_hash
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,29 @@
1
+ require 'glassfrog/base'
2
+ require 'glassfrog/rest/get'
3
+
4
+ module Glassfrog
5
+ #
6
+ # Encapsulates GlassFrog Circles.
7
+ #
8
+ class Circle < Glassfrog::Base
9
+ # @return [String]
10
+ attr_accessor :name, :short_name, :strategy
11
+ # @return [Hash]
12
+ attr_accessor :links
13
+ # @return [Array<Glassfrog::Circle]
14
+ attr_accessor :sub_circles
15
+ PATH = '/circles'
16
+ TYPE = :circles
17
+
18
+ #
19
+ # Sends a GET request for Circle(s) to GlassFrog.
20
+ # @param client [Glassfrog::Client] The client that will send the request. Contains the API key.
21
+ # @param options [Hash, Glassfrog::Base] The options used to find the correct Circles(s).
22
+ #
23
+ # @return [Array<Glassfrog::Circle>] The array of Circle(s) fetched from GlassFrog.
24
+ def self.get(client, options)
25
+ response = Glassfrog::REST::Get.get(client, PATH, options)
26
+ response[TYPE].map { |object| self.new(object) }
27
+ end
28
+ end
29
+ end