Class: OctoEvent
- Inherits:
-
Object
- Object
- OctoEvent
- Defined in:
- lib/OctoEvent.rb
Constant Summary collapse
- GITHUB_EVENT_API_END_POINT =
"https://api.github.com/%s/events"
Instance Attribute Summary collapse
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#config_url ⇒ Object
Returns the value of attribute config_url.
-
#etag_hash ⇒ Object
Returns the value of attribute etag_hash.
-
#last_event_hash ⇒ Object
Returns the value of attribute last_event_hash.
-
#parsing_block ⇒ Object
Returns the value of attribute parsing_block.
-
#sleep_period ⇒ Object
Returns the value of attribute sleep_period.
-
#target_array ⇒ Object
Returns the value of attribute target_array.
Instance Method Summary collapse
- #github_key_pair(client_id, client_secret) ⇒ Object
- #grab(event_types, &block) ⇒ Object
-
#initialize(*args, &block) ⇒ OctoEvent
constructor
A new instance of OctoEvent.
- #to_s ⇒ Object
Constructor Details
#initialize(*args, &block) ⇒ OctoEvent
Returns a new instance of OctoEvent.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/OctoEvent.rb', line 17 def initialize *args, &block @etag_hash = Hash.new "" # a hash for etags @last_event_hash = Hash.new "" # a hash for last event @sleep_period = 1 case args.size when 1 # Using a remote url to serve as the config json # Benefits? We can dynamiclly change it! # Also needs to pass in a block that does what it takes to trim the json @clnt = HTTPClient.new @config_url = args[0] @parsing_block = block when 3 # For a single target who shell never change, just provide it with github login & type name, type, etag = args @config_url = nil path = path_for name, type target_array << path @etag_hash[path] = etag end end |
Instance Attribute Details
#client_id ⇒ Object
Returns the value of attribute client_id.
11 12 13 |
# File 'lib/OctoEvent.rb', line 11 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
12 13 14 |
# File 'lib/OctoEvent.rb', line 12 def client_secret @client_secret end |
#config_url ⇒ Object
Returns the value of attribute config_url.
8 9 10 |
# File 'lib/OctoEvent.rb', line 8 def config_url @config_url end |
#etag_hash ⇒ Object
Returns the value of attribute etag_hash.
13 14 15 |
# File 'lib/OctoEvent.rb', line 13 def etag_hash @etag_hash end |
#last_event_hash ⇒ Object
Returns the value of attribute last_event_hash.
14 15 16 |
# File 'lib/OctoEvent.rb', line 14 def last_event_hash @last_event_hash end |
#parsing_block ⇒ Object
Returns the value of attribute parsing_block.
9 10 11 |
# File 'lib/OctoEvent.rb', line 9 def parsing_block @parsing_block end |
#sleep_period ⇒ Object
Returns the value of attribute sleep_period.
15 16 17 |
# File 'lib/OctoEvent.rb', line 15 def sleep_period @sleep_period end |
#target_array ⇒ Object
Returns the value of attribute target_array.
10 11 12 |
# File 'lib/OctoEvent.rb', line 10 def target_array @target_array end |
Instance Method Details
#github_key_pair(client_id, client_secret) ⇒ Object
41 42 43 44 |
# File 'lib/OctoEvent.rb', line 41 def github_key_pair client_id, client_secret @client_id = client_id @client_secret = client_secret end |
#grab(event_types, &block) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/OctoEvent.rb', line 54 def grab event_types, &block raise "nothing to do if there's no block" unless block acceptable_events = event_types.parse_event_types while true # this is a worker dyno update_target if @config_url result = {} target_array.each do |target| events = events_for target, acceptable_events result[target] = events unless events.empty? end block.call result unless result.empty? # send the result to client unless it's empty sleep sleep_period end end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/OctoEvent.rb', line 46 def to_s "Grab events for #{target_array}" end |