pager_duty_rest_client 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Lucas Parry
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,26 @@
1
+ = PagerDutyRestClient
2
+
3
+ Quick and dirty class for talking to the PagerDuty REST api. Currently only supports fetching schedules, but it should be a piece of cake to add other calls.
4
+
5
+ == Examples
6
+
7
+ client = PagerDutyRestClient.new('orgname', 'user@orgname.com', 'password')
8
+ client.get_schedule_data('ZZZ9ZZ', Time.now, Time.now) # => {"total"=>1, "entries"=>[{"end"=>"2011-08-28T23:29:00Z", "start"=>"2011-08-28T23:29:00Z", "user"=>{"name"=>"Bob Fakename", "id"=>"AAA1AAA", "email"=>"bob@orgname.com"}}]}
9
+
10
+ client.get_schedule_data('ZZZ9ZZ', Time.now, Time.now, :overflow => true) # => {"total"=>1, "entries"=>[{"end"=>"2011-08-29T10:00:00Z", "start"=>"2011-08-21T09:59:00Z", "user"=>{"name"=>"Bob Fakename", "id"=>"AAA1AAA", "email"=>"bob@orgname.com"}}]}
11
+
12
+ == Contributing to PagerDutyRestClient
13
+
14
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
15
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
16
+ * Fork the project
17
+ * Start a feature/bugfix branch
18
+ * Commit and push until you are happy with your contribution
19
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
20
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
21
+
22
+ == Copyright
23
+
24
+ Copyright (c) 2011 Lucas Parry. See LICENSE.txt for
25
+ further details.
26
+
@@ -0,0 +1,3 @@
1
+ class PagerDutyRestClient
2
+ VERSION = '0.1'
3
+ end
@@ -0,0 +1,42 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ require 'pager_duty_rest_client/version'
4
+
5
+ class PagerDutyRestClient
6
+
7
+ def initialize(org_name, username, password)
8
+ @org_name = org_name
9
+ @username = username
10
+ @password = password
11
+ end
12
+
13
+ def get_schedule_data(code, from, to, extra_args = {})
14
+ path = "/api/v1/schedules/#{code}/entries"
15
+ form_data = {
16
+ 'since' => pagerduty_time_string(from),
17
+ 'until' => pagerduty_time_string(to)
18
+ }.merge(extra_args)
19
+ authenticated_get(path, form_data)
20
+ end
21
+
22
+ private
23
+
24
+ def authenticated_get(path, form_data)
25
+ url = URI.parse("http://#{@org_name}.pagerduty.com#{path}")
26
+ req = Net::HTTP::Get.new(url.path)
27
+ req.basic_auth @username, @password
28
+ req.set_form_data(form_data, ';')
29
+ res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
30
+ case res
31
+ when Net::HTTPSuccess, Net::HTTPRedirection
32
+ JSON.parse(res.body)
33
+ else
34
+ res.error!
35
+ end
36
+
37
+ end
38
+
39
+ def pagerduty_time_string(time)
40
+ time.getutc.strftime("%Y-%m-%dT%H:%M+0")
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pager_duty_rest_client
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - Lucas Parry
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-08-29 00:00:00 +10:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: Quick and Dirty interface to the PagerDuty REST api!
35
+ email:
36
+ - lparry@gmail.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files: []
42
+
43
+ files:
44
+ - lib/pager_duty_rest_client/version.rb
45
+ - lib/pager_duty_rest_client.rb
46
+ - LICENSE.txt
47
+ - README.rdoc
48
+ has_rdoc: true
49
+ homepage: http://github.com/lparry/pager_duty_rest_client
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 3
63
+ segments:
64
+ - 0
65
+ version: "0"
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 23
72
+ segments:
73
+ - 1
74
+ - 3
75
+ - 6
76
+ version: 1.3.6
77
+ requirements: []
78
+
79
+ rubyforge_project:
80
+ rubygems_version: 1.6.2
81
+ signing_key:
82
+ specification_version: 3
83
+ summary: Quick and Dirty interface to the PagerDuty REST api
84
+ test_files: []
85
+