happyapps 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/happyapps.gemspec +23 -0
- data/lib/happyapps.rb +7 -0
- data/lib/happyapps/api_client.rb +26 -0
- data/lib/happyapps/checks_interface.rb +50 -0
- data/lib/happyapps/version.rb +3 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6e62be9aece618241fd3f45b876ac30cba72d299
|
4
|
+
data.tar.gz: 802ea7adff213edbde9f04982f104384d05117c2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 96f631fea4360476fec3ab1c294f7ba79757d554d845b8f140366d414da5d40c17dfc8c22bade7f50f9cbbc7e587e4bb6e710afd6fdae2479c828551b8cd2bfe
|
7
|
+
data.tar.gz: cc301a272a94cb957dda595b6d233bebb1abf48d71077d8adcda64bc298b7f769a4d32c82eed022bd952ff405e722f85dc7b44771f1ef52dc79ef7d0646a0f0c
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 David Estes
|
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,29 @@
|
|
1
|
+
# Happyapps
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'happyapps'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install happyapps
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/happyapps/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/happyapps.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'happyapps/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "happyapps"
|
8
|
+
spec.version = HappyApps::VERSION
|
9
|
+
spec.authors = ["David Estes"]
|
10
|
+
spec.email = ["davydotcom@gmail.com"]
|
11
|
+
spec.summary = "A small API library for interfacing with the HappyApps API"
|
12
|
+
spec.description = "Provides methods to query and update data sets within happyapps.io API"
|
13
|
+
spec.homepage = "http://www.happyapps.io"
|
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
|
+
spec.add_dependency 'rest-client'
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/lib/happyapps.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
class HappyApps::APIClient
|
5
|
+
def initialize(access_token, refresh_token,expires_in = nil, base_url=nil)
|
6
|
+
@access_token = access_token
|
7
|
+
@refresh_token = refresh_token
|
8
|
+
@base_url = base_url
|
9
|
+
if expires_in != nil
|
10
|
+
@expires_at = DateTime.now + expires_in.seconds
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.authorize(username,password,client_id='ha-customer',base_url='https://api.happyapps.io/')
|
15
|
+
authorize_response = RestClient.post "#{base_url}oauth/token", {grant_type: 'password', scope:'write', client_id: client_id, username: username, password: password}
|
16
|
+
|
17
|
+
credentials = JSON.parse(authorize_response.to_s)
|
18
|
+
|
19
|
+
return self.new(credentials['access_token'],credentials['refresh_token'],credentials['expires_at'], base_url)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
def checks
|
24
|
+
HappyApps::ChecksInterface.new(@access_token, @refresh_token, @expires_at, @base_url)
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'rest-client'
|
3
|
+
|
4
|
+
class HappyApps::ChecksInterface < HappyApps::APIClient
|
5
|
+
def initialize(access_token, refresh_token,expires_at = nil, base_url=nil)
|
6
|
+
@access_token = access_token
|
7
|
+
@refresh_token = refresh_token
|
8
|
+
@base_url = base_url
|
9
|
+
@expires_at = expires_at
|
10
|
+
end
|
11
|
+
|
12
|
+
|
13
|
+
def get(options=nil)
|
14
|
+
url = "#{@base_url}api/checks"
|
15
|
+
headers = { params: {}, authorization: "Bearer #{@access_token}" }
|
16
|
+
|
17
|
+
if options.is_a?(Hash)
|
18
|
+
headers.params.merge!(options)
|
19
|
+
elsif options.is_a?(Numeric)
|
20
|
+
url = "#{@base_url}api/checks/#{options}"
|
21
|
+
elsif options.is_a?(String)
|
22
|
+
headers.params['name'] = options
|
23
|
+
end
|
24
|
+
response = RestClient::Request.execute(method: :get, url: url,
|
25
|
+
timeout: 10, headers: headers)
|
26
|
+
JSON.parse(response.to_s)
|
27
|
+
end
|
28
|
+
|
29
|
+
def history(id, params={})
|
30
|
+
url = "#{@base_url}api/checks/#{id}/history"
|
31
|
+
headers = { params: params, authorization: "Bearer #{@access_token}" }
|
32
|
+
response = RestClient::Request.execute(method: :get, url: url,
|
33
|
+
timeout: 10, headers: headers)
|
34
|
+
JSON.parse(response.to_s)
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def create(options)
|
39
|
+
url = "#{@base_url}api/checks"
|
40
|
+
headers = { :authorization => "Bearer #{@access_token}", 'Content-Type' => 'application/json' }
|
41
|
+
if options[:config] != nil && options[:config].is_a?(Hash)
|
42
|
+
options[:config] = options[:config].to_json
|
43
|
+
end
|
44
|
+
payload = {check: options}
|
45
|
+
puts "Saving with payload: #{payload.to_json}"
|
46
|
+
response = RestClient::Request.execute(method: :post, url: url,
|
47
|
+
timeout: 10, headers: headers, payload: payload.to_json)
|
48
|
+
JSON.parse(response.to_s)
|
49
|
+
end
|
50
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: happyapps
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- David Estes
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-06-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rest-client
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.6'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
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
|
+
description: Provides methods to query and update data sets within happyapps.io API
|
56
|
+
email:
|
57
|
+
- davydotcom@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- happyapps.gemspec
|
68
|
+
- lib/happyapps.rb
|
69
|
+
- lib/happyapps/api_client.rb
|
70
|
+
- lib/happyapps/checks_interface.rb
|
71
|
+
- lib/happyapps/version.rb
|
72
|
+
homepage: http://www.happyapps.io
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: A small API library for interfacing with the HappyApps API
|
96
|
+
test_files: []
|