harmonyrb 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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/README.md +48 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/harmony.gemspec +27 -0
- data/lib/harmony/client.rb +91 -0
- data/lib/harmony/errors.rb +22 -0
- data/lib/harmony/model.rb +158 -0
- data/lib/harmony/models/event.rb +12 -0
- data/lib/harmony/models/group.rb +18 -0
- data/lib/harmony/models/result.rb +12 -0
- data/lib/harmony/models/user.rb +19 -0
- data/lib/harmony/models/watch.rb +29 -0
- data/lib/harmony/services/clients.rb +59 -0
- data/lib/harmony/services/events.rb +24 -0
- data/lib/harmony/services/groups.rb +31 -0
- data/lib/harmony/services/results.rb +18 -0
- data/lib/harmony/services/subscribers.rb +32 -0
- data/lib/harmony/services/users.rb +31 -0
- data/lib/harmony/services/watches.rb +31 -0
- data/lib/harmony/version.rb +3 -0
- data/lib/harmony.rb +6 -0
- metadata +139 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b6ebe1934dd19cace83736cdf68ad95a0c1ade34
|
4
|
+
data.tar.gz: 34d16178a451d2376d8bcaf9e7c905aa5bc9d110
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8cc2ce45b626dec5ce61124677c0efbe31d3db235a00819ab3d5b30f78447d6e2385aa1f08b75a2f74f1d2781b9ae5f27d4576ac849ac34ffe1f2c9bf42821cf
|
7
|
+
data.tar.gz: b02728603cad948837730123da56b494a441003ec23936faa0664efa8e0ec06284206581e87fd5df0780403e1600b5565ffcc3936e06de9d360864d6563b5c39
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Harmony
|
2
|
+
|
3
|
+
Harmony is an application and service monitoring app. This gem wraps the harmony api and providers you
|
4
|
+
full read/write access depending on user authentication.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Add this line to your application's Gemfile:
|
9
|
+
|
10
|
+
```ruby
|
11
|
+
gem 'harmony'
|
12
|
+
```
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install harmony
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
Using the api is fairly straight forward. First you will need to create an account
|
25
|
+
at [Harmony](http://harmony.s1.skylarklabs.com)
|
26
|
+
|
27
|
+
Then you will need to create a client
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
client = Harmony::Client.new {
|
31
|
+
access_token: 'adfhsljfalksdfja89jvsnallksdfj'
|
32
|
+
|
33
|
+
}
|
34
|
+
```
|
35
|
+
|
36
|
+
## Development
|
37
|
+
|
38
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
39
|
+
|
40
|
+
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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
41
|
+
|
42
|
+
## Contributing
|
43
|
+
|
44
|
+
1. Fork it ( https://github.com/[my-github-username]/harmony/fork )
|
45
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
46
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
47
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
48
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "harmony"
|
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
data/harmony.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'harmony/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "harmonyrb"
|
8
|
+
spec.version = Harmony::VERSION
|
9
|
+
spec.authors = ["Sam John Duke"]
|
10
|
+
spec.email = ["mail@samjohnduke.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby gem that wraps the harmony api}
|
13
|
+
spec.description = %q{Ruby gem that wraps the harmony api}
|
14
|
+
spec.homepage = "http://harmonyrb.s1.skylarklabs.com"
|
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
|
+
spec.add_dependency "http", "~> 0.9.4"
|
22
|
+
spec.add_dependency "oauth2", "~> 1.0.0"
|
23
|
+
spec.add_dependency "activesupport", "~> 4.2.4"
|
24
|
+
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
27
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'harmony/services/clients'
|
2
|
+
require 'http'
|
3
|
+
require 'oauth2'
|
4
|
+
|
5
|
+
module Harmony
|
6
|
+
class Client
|
7
|
+
attr_accessor :api_endpoint
|
8
|
+
attr_accessor :api_namespace
|
9
|
+
attr_accessor :client_id
|
10
|
+
attr_accessor :client_secret
|
11
|
+
attr_accessor :access_token
|
12
|
+
attr_accessor :refresh_token
|
13
|
+
attr_accessor :grant_type
|
14
|
+
attr_accessor :user_agent
|
15
|
+
|
16
|
+
def initialize opts={}
|
17
|
+
@api_endpoint = 'http://harmony.s1.skylarklabs.com/'
|
18
|
+
@api_namespace = 'api/v1/'
|
19
|
+
|
20
|
+
opts.each do |k,v|
|
21
|
+
instance_variable_set(:"@#{k}", v)
|
22
|
+
end
|
23
|
+
|
24
|
+
@services = {}
|
25
|
+
end
|
26
|
+
|
27
|
+
def get path, options = {}
|
28
|
+
execute :get, path, {}, options
|
29
|
+
end
|
30
|
+
|
31
|
+
def post path, data={}, options = {}
|
32
|
+
execute :post, path, data, options
|
33
|
+
end
|
34
|
+
|
35
|
+
def put path, data={}, options = {}
|
36
|
+
execute :put, path, data, options
|
37
|
+
end
|
38
|
+
|
39
|
+
def patch path, data={}, options = {}
|
40
|
+
execute :patch, path, data, options
|
41
|
+
end
|
42
|
+
|
43
|
+
def delete path, options = {}
|
44
|
+
execute :delete, path, {}, options
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def api_path p
|
50
|
+
@api_endpoint + @api_namespace + p
|
51
|
+
end
|
52
|
+
|
53
|
+
def execute(method, path, data, options = {})
|
54
|
+
response = request(method, path, data, options)
|
55
|
+
|
56
|
+
case response.code
|
57
|
+
when 200..299
|
58
|
+
response
|
59
|
+
when 401
|
60
|
+
raise AuthenticationFailed, response["message"]
|
61
|
+
when 404
|
62
|
+
raise NotFoundError.new(response)
|
63
|
+
else
|
64
|
+
raise RequestError.new(response)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def request(method, path, data, options = {})
|
69
|
+
options.merge!(defaults)
|
70
|
+
if method == :get || method == :delete
|
71
|
+
HTTP.accept(:json).headers(options).send method, api_path(path)
|
72
|
+
elsif method == :post or method == :put or method == :patch
|
73
|
+
HTTP.accept(:json).headers(options).send method, api_path(path), json: data
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def defaults
|
78
|
+
default = {}
|
79
|
+
unless @access_token
|
80
|
+
client = OAuth2::Client.new(@client_id, @client_secret, :site => @api_endpoint)
|
81
|
+
@access_token = client.client_credentials.get_token.headers["Authorization"]
|
82
|
+
end
|
83
|
+
default["Authorization"] = @access_token
|
84
|
+
default
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
require 'harmony/model'
|
91
|
+
require 'harmony/errors'
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Harmony
|
2
|
+
class Error < StandardError
|
3
|
+
end
|
4
|
+
|
5
|
+
class RequestError < Error
|
6
|
+
attr_reader :response
|
7
|
+
|
8
|
+
def initialize(response)
|
9
|
+
@response = response
|
10
|
+
super("#{response.code}")
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class NotFoundError < RequestError
|
15
|
+
end
|
16
|
+
|
17
|
+
class AuthenticationError < Error
|
18
|
+
end
|
19
|
+
|
20
|
+
class AuthenticationFailed < AuthenticationError
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
require 'active_support/inflector/inflections'
|
2
|
+
require 'active_support/core_ext/string'
|
3
|
+
|
4
|
+
module Harmony
|
5
|
+
module Model
|
6
|
+
|
7
|
+
class Collection < Struct.new(:client, :klass, :results, :meta)
|
8
|
+
|
9
|
+
def next_page_num
|
10
|
+
meta["next_page"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def next_page
|
14
|
+
next_page = nil
|
15
|
+
if next_page_num
|
16
|
+
response = client.get path, {}, :params => {page: next_page_num}
|
17
|
+
self.class.build_collection response
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def prev_page_num
|
22
|
+
meta["prev_page"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def num_pages
|
26
|
+
meta["total_pages"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def current_page
|
30
|
+
meta["current_page"]
|
31
|
+
end
|
32
|
+
|
33
|
+
def num_results
|
34
|
+
meta["total_count"]
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.build_collection response
|
38
|
+
groups = b["groups"].map { |r| Model::Group.new(client, r) }
|
39
|
+
Model::Collection.new client, Model::Group, groups, b["meta"]
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class Base
|
44
|
+
attr_accessor :client
|
45
|
+
|
46
|
+
def initialize(conn, attributes = {})
|
47
|
+
@client = conn
|
48
|
+
attributes.each do |key, value|
|
49
|
+
m = "#{key}=".to_sym
|
50
|
+
self.send(m, value) if self.respond_to?(m)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Create a model based on the data provided
|
55
|
+
def create
|
56
|
+
req = client.send :post, path, to_h
|
57
|
+
end
|
58
|
+
|
59
|
+
# Delete a model
|
60
|
+
def destroy
|
61
|
+
req = client.send :delete, path
|
62
|
+
end
|
63
|
+
|
64
|
+
# Update a model
|
65
|
+
def update
|
66
|
+
req = client.send :patch, path, to_h
|
67
|
+
end
|
68
|
+
|
69
|
+
def to_h
|
70
|
+
attrs = {}
|
71
|
+
@@attrs.each do |a|
|
72
|
+
m = "#{key}".to_sym
|
73
|
+
@attrs[a] = self.send(m) if self.respond_to?(m)
|
74
|
+
end
|
75
|
+
attrs
|
76
|
+
end
|
77
|
+
|
78
|
+
def to_json
|
79
|
+
to_h.to_json
|
80
|
+
end
|
81
|
+
|
82
|
+
def path
|
83
|
+
@@path
|
84
|
+
end
|
85
|
+
|
86
|
+
class << self
|
87
|
+
# Add 1 or more attributes to the model
|
88
|
+
def attributes(*args)
|
89
|
+
@@attrs ||= []
|
90
|
+
|
91
|
+
#We simply iterate through each passed in argument...
|
92
|
+
args.each do |arg|
|
93
|
+
self.class_eval("def #{arg};@#{arg};end")
|
94
|
+
self.class_eval("def #{arg}=(val);@#{arg}=val;end")
|
95
|
+
|
96
|
+
#store arg in array
|
97
|
+
@@attrs << arg
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def path p
|
102
|
+
@@path = p
|
103
|
+
end
|
104
|
+
|
105
|
+
def has_many member
|
106
|
+
self.class_eval <<-CODE
|
107
|
+
class #{member.to_s.capitalize}Service < ::Struct.new(:client, :parent)
|
108
|
+
include Harmony::Client::#{member.to_s.capitalize}
|
109
|
+
|
110
|
+
def path
|
111
|
+
"#{@@path}/\#{parent.id}/#{member.to_s}"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def #{member.to_s} id=nil
|
116
|
+
@s ||= {}
|
117
|
+
@s[:#{member.to_s}] ||= #{member.to_s.capitalize}Service.new(client, self)
|
118
|
+
if id == nil
|
119
|
+
@s[:#{member.to_s}].all
|
120
|
+
else
|
121
|
+
return nil unless @s[:#{member.to_s}].respond_to? find
|
122
|
+
@s[:#{member.to_s}].find(id)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
CODE
|
126
|
+
end
|
127
|
+
|
128
|
+
def belongs_to member
|
129
|
+
self.class_eval <<-CODE
|
130
|
+
class #{member.to_s.capitalize}Service < ::Struct.new(:client)
|
131
|
+
include Harmony::Client::#{member.to_s.capitalize.pluralize}
|
132
|
+
|
133
|
+
def path
|
134
|
+
"#{member.to_s.pluralize}"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
def #{member.to_s}
|
139
|
+
@s ||= {}
|
140
|
+
@s[:#{member.to_s}] ||= #{member.to_s.capitalize}Service.new(client)
|
141
|
+
if self.#{member.to_s}_id != nil
|
142
|
+
@s[:#{member.to_s}].find(self.#{member.to_s}_id)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
CODE
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
require 'harmony/models/event'
|
155
|
+
require 'harmony/models/group'
|
156
|
+
require 'harmony/models/result'
|
157
|
+
require 'harmony/models/user'
|
158
|
+
require 'harmony/models/watch'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Harmony
|
2
|
+
module Model
|
3
|
+
class Group < Base
|
4
|
+
attributes :id
|
5
|
+
attributes :name
|
6
|
+
attributes :description
|
7
|
+
attributes :created_at
|
8
|
+
attributes :updated_at
|
9
|
+
attributes :links
|
10
|
+
|
11
|
+
path 'groups'
|
12
|
+
|
13
|
+
has_many :watches
|
14
|
+
has_many :subscribers
|
15
|
+
has_many :results
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Harmony
|
2
|
+
module Model
|
3
|
+
class User < Base
|
4
|
+
attributes :id
|
5
|
+
attributes :name
|
6
|
+
attributes :email
|
7
|
+
attributes :role
|
8
|
+
attributes :sign_in_count
|
9
|
+
attributes :current_sign_in_at
|
10
|
+
attributes :last_sign_in_at
|
11
|
+
attributes :current_sign_in_ip
|
12
|
+
attributes :last_sign_in_ip
|
13
|
+
attributes :created_at
|
14
|
+
attributes :updated_at
|
15
|
+
attributes :deleted_at
|
16
|
+
attributes :links
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Harmony
|
2
|
+
module Model
|
3
|
+
class Watch < Base
|
4
|
+
attributes :id
|
5
|
+
attributes :uri
|
6
|
+
attributes :contains
|
7
|
+
attributes :excludes
|
8
|
+
attributes :aasm_status
|
9
|
+
attributes :group_id
|
10
|
+
attributes :last_update
|
11
|
+
attributes :query_interval
|
12
|
+
attributes :created_at
|
13
|
+
attributes :updated_at
|
14
|
+
attributes :deleted_at
|
15
|
+
attributes :watch_type
|
16
|
+
attributes :next_update
|
17
|
+
attributes :status_threshold
|
18
|
+
attributes :status_count
|
19
|
+
attributes :links
|
20
|
+
|
21
|
+
path 'watches'
|
22
|
+
|
23
|
+
has_many :results
|
24
|
+
has_many :events
|
25
|
+
|
26
|
+
belongs_to :group
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module Harmony
|
2
|
+
class Client
|
3
|
+
def groups
|
4
|
+
@services[:groups] ||= Client::GroupsService.new(self)
|
5
|
+
end
|
6
|
+
|
7
|
+
def users
|
8
|
+
@services[:users] ||= Client::UsersService.new(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
class ClientService < ::Struct.new(:client)
|
13
|
+
end
|
14
|
+
|
15
|
+
|
16
|
+
require 'harmony/services/groups'
|
17
|
+
|
18
|
+
class GroupsService < ClientService
|
19
|
+
include Client::Groups
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'harmony/services/users'
|
23
|
+
|
24
|
+
class UsersService < ClientService
|
25
|
+
include Client::Users
|
26
|
+
end
|
27
|
+
|
28
|
+
require 'harmony/services/watches'
|
29
|
+
|
30
|
+
class WatchesService < ClientService
|
31
|
+
include Client::Watches
|
32
|
+
end
|
33
|
+
|
34
|
+
require 'harmony/services/events'
|
35
|
+
|
36
|
+
class EventsService < ClientService
|
37
|
+
include Client::Events
|
38
|
+
end
|
39
|
+
|
40
|
+
require 'harmony/services/watches'
|
41
|
+
|
42
|
+
class WatchesService < ClientService
|
43
|
+
include Client::Watches
|
44
|
+
end
|
45
|
+
|
46
|
+
require 'harmony/services/subscribers'
|
47
|
+
|
48
|
+
class SubscriptionsService < ClientService
|
49
|
+
include Client::Subscribers
|
50
|
+
end
|
51
|
+
|
52
|
+
require 'harmony/services/results'
|
53
|
+
|
54
|
+
class ResultsService < ClientService
|
55
|
+
include Client::Results
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module Harmony
|
2
|
+
class Client
|
3
|
+
module Events
|
4
|
+
|
5
|
+
def all(opts={})
|
6
|
+
response = client.get(path, opts)
|
7
|
+
b = JSON.parse(response.body.to_s)
|
8
|
+
groups = b["events"].map { |r| Model::Event.new(client, r) }
|
9
|
+
Model::Collection.new client, Model::Event, groups, b["meta"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(id)
|
13
|
+
response = client.get("#{path}/#{group_id}")
|
14
|
+
b = JSON.parse(response.body.to_s)
|
15
|
+
Model::Event.new(client, b["event"])
|
16
|
+
end
|
17
|
+
|
18
|
+
def path
|
19
|
+
'events'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Harmony
|
2
|
+
class Client
|
3
|
+
module Groups
|
4
|
+
|
5
|
+
def all(opts={})
|
6
|
+
response = client.get(path, opts)
|
7
|
+
b = JSON.parse(response.body.to_s)
|
8
|
+
groups = b["groups"].map { |r| Model::Group.new(client, r) }
|
9
|
+
Model::Collection.new client, Model::Group, groups, b["meta"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(group_id)
|
13
|
+
response = client.get("#{path}/#{group_id}")
|
14
|
+
b = JSON.parse(response.body.to_s)
|
15
|
+
Model::Group.new(client, b["group"])
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(attributes = {})
|
19
|
+
options = { group: attributes }
|
20
|
+
response = client.post(path, options)
|
21
|
+
b = JSON.parse(response.body.to_s)
|
22
|
+
Model::Group.new(client, b["group"])
|
23
|
+
end
|
24
|
+
|
25
|
+
def path
|
26
|
+
'groups'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Harmony
|
2
|
+
class Client
|
3
|
+
module Results
|
4
|
+
|
5
|
+
def all(opts={})
|
6
|
+
response = client.get(path, opts)
|
7
|
+
b = JSON.parse(response.body.to_s)
|
8
|
+
groups = b["results"].map { |r| Model::Result.new(client, r) }
|
9
|
+
Model::Collection.new client, Model::Result, groups, b["meta"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def path
|
13
|
+
'results'
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module Harmony
|
2
|
+
class Client
|
3
|
+
module Subscribers
|
4
|
+
|
5
|
+
def all(opts={})
|
6
|
+
response = client.get('groups', opts)
|
7
|
+
b = JSON.parse(response.body.to_s)
|
8
|
+
groups = b["subscribers"].map { |r| Model::Subscriber.new(client, r) }
|
9
|
+
Model::Collection.new client, Model::Subscriber, groups, b["meta"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(group_id)
|
13
|
+
response = client.get("#{path}/#{group_id}")
|
14
|
+
b = JSON.parse(response.body.to_s)
|
15
|
+
Model::Subscriber.new(client, b["subscriber"])
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(attributes = {})
|
19
|
+
options = { subscriber: attributes }
|
20
|
+
response = client.post(path, options)
|
21
|
+
b = JSON.parse(response.body.to_s)
|
22
|
+
Model::Subscriber.new(client, b["subscriber"])
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def path
|
27
|
+
'subscribers'
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Harmony
|
2
|
+
class Client
|
3
|
+
module Users
|
4
|
+
|
5
|
+
def all(opts={})
|
6
|
+
response = client.get(path, opts)
|
7
|
+
b = JSON.parse(response.body.to_s)
|
8
|
+
groups = b["users"].map { |r| Model::User.new(client, r) }
|
9
|
+
Model::Collection.new client, Model::User, groups, b["meta"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(id)
|
13
|
+
response = client.get("#{path}/#{id}")
|
14
|
+
b = JSON.parse(response.body.to_s)
|
15
|
+
Model::User.new(client, b["user"])
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(attributes = {})
|
19
|
+
options = { user: attributes }
|
20
|
+
response = client.post(path, options)
|
21
|
+
b = JSON.parse(response.body.to_s)
|
22
|
+
Model::User.new(client, b["user"])
|
23
|
+
end
|
24
|
+
|
25
|
+
def path
|
26
|
+
'users'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Harmony
|
2
|
+
class Client
|
3
|
+
module Watches
|
4
|
+
|
5
|
+
def all(opts={})
|
6
|
+
response = client.get(path, opts)
|
7
|
+
b = JSON.parse(response.body.to_s)
|
8
|
+
groups = b["watches"].map { |r| Model::Watch.new(client, r) }
|
9
|
+
Model::Collection.new client, Model::Watch, groups, b["meta"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(watch_id)
|
13
|
+
response = client.get("#{path}/#{watch_id}")
|
14
|
+
b = JSON.parse(response.body.to_s)
|
15
|
+
Model::Watch.new(client, b["watch"])
|
16
|
+
end
|
17
|
+
|
18
|
+
def create(attributes = {})
|
19
|
+
options = { watch: attributes }
|
20
|
+
response = client.post(path, options)
|
21
|
+
b = JSON.parse(response.body.to_s)
|
22
|
+
Model::Watch.new(client, b["watch"])
|
23
|
+
end
|
24
|
+
|
25
|
+
def path
|
26
|
+
'watches'
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/harmony.rb
ADDED
metadata
ADDED
@@ -0,0 +1,139 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: harmonyrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sam John Duke
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-09-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: http
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.9.4
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.9.4
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: oauth2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: activesupport
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 4.2.4
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 4.2.4
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.9'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.9'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: Ruby gem that wraps the harmony api
|
84
|
+
email:
|
85
|
+
- mail@samjohnduke.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rspec"
|
92
|
+
- ".travis.yml"
|
93
|
+
- Gemfile
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- harmony.gemspec
|
99
|
+
- lib/harmony.rb
|
100
|
+
- lib/harmony/client.rb
|
101
|
+
- lib/harmony/errors.rb
|
102
|
+
- lib/harmony/model.rb
|
103
|
+
- lib/harmony/models/event.rb
|
104
|
+
- lib/harmony/models/group.rb
|
105
|
+
- lib/harmony/models/result.rb
|
106
|
+
- lib/harmony/models/user.rb
|
107
|
+
- lib/harmony/models/watch.rb
|
108
|
+
- lib/harmony/services/clients.rb
|
109
|
+
- lib/harmony/services/events.rb
|
110
|
+
- lib/harmony/services/groups.rb
|
111
|
+
- lib/harmony/services/results.rb
|
112
|
+
- lib/harmony/services/subscribers.rb
|
113
|
+
- lib/harmony/services/users.rb
|
114
|
+
- lib/harmony/services/watches.rb
|
115
|
+
- lib/harmony/version.rb
|
116
|
+
homepage: http://harmonyrb.s1.skylarklabs.com
|
117
|
+
licenses: []
|
118
|
+
metadata: {}
|
119
|
+
post_install_message:
|
120
|
+
rdoc_options: []
|
121
|
+
require_paths:
|
122
|
+
- lib
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ">="
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 2.4.5
|
136
|
+
signing_key:
|
137
|
+
specification_version: 4
|
138
|
+
summary: Ruby gem that wraps the harmony api
|
139
|
+
test_files: []
|