pager_duty_rest_client 0.2 → 0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # PagerDutyRestClient
2
+
3
+ Quick and dirty class for talking to the PagerDuty REST api.
4
+
5
+ ## Examples
6
+
7
+ ### instantiation:
8
+ client = PagerDutyRestClient.new('orgname', 'user@orgname.com', 'password')
9
+
10
+ ### get_schedule_data:
11
+
12
+ client.get_schedule_data('ZZZ9ZZ', Time.now, Time.now)
13
+ # => {"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"}}]}
14
+
15
+ client.get_schedule_data('ZZZ9ZZ', Time.now, Time.now, :overflow => true)
16
+ # => {"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"}}]}
17
+
18
+ ### get_incident_count:
19
+
20
+ client.get_incidents_count
21
+ # => {"total"=>72}
22
+
23
+ ### get_incident_data:
24
+
25
+ client.get_incidents_data('since'=>'2011-08-29T11:41+10')
26
+ # => {"incidents"=>[{"assigned_to_user"=>nil, "last_status_change_on"=>"2011-08-29T02:15:39Z", "trigger_summary_data"=>nil, "trigger_details_html_url"=>"http://orgname.pagerduty.com/incidents/OMGCODE/log_entries/OMGINCIDNET", "created_on"=>"2011-08-29T02:07:37Z", "service"=>{"name"=>"Stuff Broked!", "id"=>"INCIDENTID", "html_url"=>"http://orgname.pagerduty.com/services/WOWOMG"}, "last_status_change_by"=>nil, "html_url"=>"http://orgname.pagerduty.com/incidents/OMGWOW", "status"=>"resolved", "incident_number"=>42, "incident_key"=>"Swanky Key"}], "total"=>1, "limit"=>100}
27
+
28
+ ## Contributing to PagerDutyRestClient
29
+
30
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
31
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
32
+ * Fork the project
33
+ * Start a feature/bugfix branch
34
+ * Commit and push until you are happy with your contribution
35
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
36
+ * 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.
37
+
38
+ ## Copyright
39
+
40
+ Copyright (c) 2011 Lucas Parry. See LICENSE.txt for
41
+ further details.
42
+
@@ -1,10 +1,18 @@
1
1
  require 'net/http'
2
2
  require 'json'
3
3
  require 'pager_duty_rest_client/version'
4
+ begin
5
+ require 'net/https'
6
+ rescue LoadError
7
+ puts "net/https was not found on your system, ssl support will not work without it"
8
+ end
4
9
 
5
10
  class PagerDutyRestClient
6
11
 
7
- def initialize(org_name, username, password)
12
+ RootCA = '/etc/ssl/certs'
13
+
14
+ def initialize(org_name, username, password, options = {})
15
+ @options = {:https => false}.merge(options)
8
16
  @org_name = org_name
9
17
  @username = username
10
18
  @password = password
@@ -31,12 +39,25 @@ class PagerDutyRestClient
31
39
 
32
40
  private
33
41
 
42
+ def use_https?
43
+ !!@options[:https]
44
+ end
45
+
46
+ def protocol
47
+ use_https? ? "https" : "http"
48
+ end
49
+
34
50
  def authenticated_get(path, form_data)
35
- url = URI.parse("http://#{@org_name}.pagerduty.com#{path}")
51
+ url = URI.parse("#{protocol}://#{@org_name}.pagerduty.com#{path}")
52
+
36
53
  req = Net::HTTP::Get.new(url.path)
37
54
  req.basic_auth @username, @password
38
55
  req.set_form_data(form_data, ';')
39
- res = Net::HTTP.new(url.host, url.port).start {|http| http.request(req) }
56
+
57
+ http = Net::HTTP.new(url.host, url.port)
58
+ configure_ssl(http) if use_https?
59
+ res = http.start {|http| http.request(req) }
60
+
40
61
  case res
41
62
  when Net::HTTPSuccess, Net::HTTPRedirection
42
63
  JSON.parse(res.body)
@@ -46,6 +67,18 @@ class PagerDutyRestClient
46
67
 
47
68
  end
48
69
 
70
+ def configure_ssl(http)
71
+ http.use_ssl = true
72
+
73
+ if File.directory? RootCA
74
+ http.ca_path = RootCA
75
+ http.verify_mode = OpenSSL::SSL::VERIFY_PEER
76
+ http.verify_depth = 5
77
+ else
78
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
79
+ end
80
+ end
81
+
49
82
  def pagerduty_time_string(time)
50
83
  time.getutc.strftime("%Y-%m-%dT%H:%M+0")
51
84
  end
@@ -1,3 +1,3 @@
1
1
  class PagerDutyRestClient
2
- VERSION = '0.2'
2
+ VERSION = '0.3'
3
3
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pager_duty_rest_client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 2
9
- version: "0.2"
8
+ - 3
9
+ version: "0.3"
10
10
  platform: ruby
11
11
  authors:
12
12
  - Lucas Parry
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-08-29 00:00:00 +10:00
17
+ date: 2011-12-15 00:00:00 +11:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -44,7 +44,7 @@ files:
44
44
  - lib/pager_duty_rest_client/version.rb
45
45
  - lib/pager_duty_rest_client.rb
46
46
  - LICENSE.txt
47
- - README.rdoc
47
+ - README.md
48
48
  has_rdoc: true
49
49
  homepage: http://github.com/lparry/pager_duty_rest_client
50
50
  licenses: []
data/README.rdoc DELETED
@@ -1,26 +0,0 @@
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
-