circonus-api 0.0.1

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.
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in circonus-api.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ben Marini
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.
@@ -0,0 +1,40 @@
1
+ # Circonus::Api
2
+
3
+ This is a gem for interacting with the [Circonus API](http://circonus.com/resources/api).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'circonus-api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install circonus-api
18
+
19
+ ## Usage
20
+
21
+ This gem provides a pretty simple interface to the Circonus API.
22
+
23
+ # you can also set CIRCONUS_APP_NAME and CIRCONUS_API_TOKEN env vars and
24
+ # not pass any arguments.
25
+ api = Circonus::Api.new(app_name, api_token)
26
+
27
+ # Each resource has the following methods, using Accounts as an example
28
+ api.list_accounts
29
+ api.show_account(id)
30
+ api.create_account(json_data)
31
+ api.update_account(id, json_data)
32
+ api.delete_account(id)
33
+
34
+ ## Contributing
35
+
36
+ 1. Fork it
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # This script just provides quick and dirty access to the API, not meant to
4
+ # be that useful.
5
+ #
6
+ # Usage: CIRCONUS_APP_NAME=appname CIRCONUS_API_TOKEN=apitoken ./bin/circonus-api list_accounts
7
+ require 'rubygems'
8
+ require 'bundler/setup'
9
+ require 'circonus-api'
10
+
11
+ api = Circonus::Api.new
12
+ method = ARGV.shift
13
+ p api.send(method, *ARGV)
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'circonus-api/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "circonus-api"
8
+ gem.version = Circonus::Api::VERSION
9
+ gem.authors = ["Ben Marini"]
10
+ gem.email = ["bmarini@gmail.com"]
11
+ gem.description = %q{Ruby client for the Circonus API}
12
+ gem.summary = %q{Ruby client for the Circonus API}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_runtime_dependency "rest-client"
20
+ gem.add_runtime_dependency "json"
21
+ end
@@ -0,0 +1,72 @@
1
+ require "circonus-api/version"
2
+ require "rest-client"
3
+ require "json"
4
+ require "uri"
5
+
6
+ module Circonus
7
+ class Api
8
+ def initialize(app_name=nil, api_token=nil)
9
+ app_name ||= ENV['CIRCONUS_APP_NAME']
10
+ api_token ||= ENV['CIRCONUS_API_TOKEN']
11
+
12
+ @resource = RestClient::Resource.new('https://api.circonus.com',
13
+ :headers => {
14
+ :x_circonus_app_name => app_name,
15
+ :x_circonus_auth_token => api_token,
16
+ :accept => 'application/json'
17
+ }
18
+ )
19
+ end
20
+
21
+ def self.resource( plural_name, singular_name = plural_name.gsub(/s$/, '') )
22
+ define_method("list_#{plural_name}") { get("/#{singular_name}") }
23
+ define_method("show_#{singular_name}") { |id| get("/#{singular_name}/#{id}") }
24
+ define_method("create_#{singular_name}") { |data| post("/#{singular_name}", data) }
25
+ define_method("update_#{singular_name}") { |id, data| put("/#{singular_name}/#{id}", data) }
26
+ define_method("delete_#{singular_name}") { |id| delete("/#{singular_name}/#{id}") }
27
+ end
28
+
29
+ resource "accounts"
30
+ resource "annotations"
31
+ resource "brokers"
32
+ resource "check_bundles"
33
+ resource "contact_groups"
34
+ resource "graphs"
35
+ resource "rule_sets"
36
+ resource "templates"
37
+ resource "users"
38
+ resource "worksheets"
39
+
40
+ def get(path, params={})
41
+ request(:get, path, params)
42
+ end
43
+
44
+ def put(path, params={})
45
+ request(:put, path, params.to_json)
46
+ end
47
+
48
+ def post(path, params={})
49
+ request(:post, path, params.to_json)
50
+ end
51
+
52
+ def delete(path, params={})
53
+ request(:delete, path, params)
54
+ end
55
+
56
+ def request(method, path, params)
57
+ begin
58
+ response = @resource[URI.escape(path)].send(method, params)
59
+ result = deserialize(response)
60
+ rescue RestClient::Exception => e
61
+ result = deserialize(e.http_body)
62
+ end
63
+
64
+ return result
65
+ end
66
+
67
+ def deserialize(json_string)
68
+ JSON.parse(json_string)
69
+ end
70
+
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Circonus
2
+ class Api
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: circonus-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ben Marini
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: &70105227303660 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70105227303660
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &70105227302360 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70105227302360
36
+ description: Ruby client for the Circonus API
37
+ email:
38
+ - bmarini@gmail.com
39
+ executables:
40
+ - circonus-api
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE.txt
47
+ - README.md
48
+ - Rakefile
49
+ - bin/circonus-api
50
+ - circonus-api.gemspec
51
+ - lib/circonus-api.rb
52
+ - lib/circonus-api/version.rb
53
+ homepage: ''
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.11
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Ruby client for the Circonus API
77
+ test_files: []
78
+ has_rdoc: