Class: EventGirl::Client
- Inherits:
-
Object
- Object
- EventGirl::Client
- Defined in:
- lib/event_girl_client.rb
Constant Summary collapse
- VERSION =
'1.2.1'
- @@api_token =
Class-wide configuration
nil
- @@url =
nil
Instance Attribute Summary collapse
-
#api_token ⇒ Object
readonly
Returns the value of attribute api_token.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(url = nil, api_token = nil) ⇒ Client
constructor
A new instance of Client.
-
#send!(title, content = nil) ⇒ Object
POSTs a string to the event_girl server.
-
#send_event(*args) ⇒ Object
deprecated
Deprecated.
Use #send! instead.
Constructor Details
#initialize(url = nil, api_token = nil) ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 |
# File 'lib/event_girl_client.rb', line 18 def initialize(url = nil, api_token = nil) @url = (url || self.class.url) @api_token = (api_token || self.class.api_token).to_s raise ArgumentError.new('No url provided.') unless @url end |
Instance Attribute Details
#api_token ⇒ Object (readonly)
Returns the value of attribute api_token.
16 17 18 |
# File 'lib/event_girl_client.rb', line 16 def api_token @api_token end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
16 17 18 |
# File 'lib/event_girl_client.rb', line 16 def url @url end |
Class Method Details
.configure {|_self| ... } ⇒ Object
56 57 58 |
# File 'lib/event_girl_client.rb', line 56 def self.configure yield self if block_given? end |
Instance Method Details
#send!(title, content = nil) ⇒ Object
POSTs a string to the event_girl server.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/event_girl_client.rb', line 30 def send!(title, content = nil) uri = URI.parse(url) # Auto-correct missing trailing slash path = uri.path == '' ? '/' : uri.path # This is all the post request stuff. req = Net::HTTP::Post.new(path) # The request format and content type is json req['Accept'] = "application/json" req['Content-Type'] = "application/json" # This takes the entered api token and title. This is what is sent. It is a HASH! req.body = '{"api_token":"' + api_token + '","incoming_event":{"title":"' + title.to_s + '","content":"' + content.to_s + '"}}' # The request is sent via HTTP to the host and port. You also get a response # ex: 201 (it worked) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = ssl? http.verify_mode = OpenSSL::SSL::VERIFY_NONE http.request(req) end |
#send_event(*args) ⇒ Object
Deprecated.
Use #send! instead.
25 26 27 |
# File 'lib/event_girl_client.rb', line 25 def send_event(*args) send!(*args) end |