Class: Gilgamesh
- Inherits:
-
Object
- Object
- Gilgamesh
- Defined in:
- lib/gilgamesh.rb,
lib/gilgamesh/version.rb
Constant Summary collapse
- VERSION =
"0.0.5"
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#conn ⇒ Object
readonly
Returns the value of attribute conn.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(api_key, api_url: "http://gcm-http.googleapis.com/gcm/send") ⇒ Gilgamesh
constructor
A new instance of Gilgamesh.
- #push(registration_token, title:, body:) ⇒ Object
Constructor Details
#initialize(api_key, api_url: "http://gcm-http.googleapis.com/gcm/send") ⇒ Gilgamesh
Returns a new instance of Gilgamesh.
9 10 11 12 |
# File 'lib/gilgamesh.rb', line 9 def initialize(api_key, api_url: "http://gcm-http.googleapis.com/gcm/send") @api_key = api_key @api_url = api_url end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
6 7 8 |
# File 'lib/gilgamesh.rb', line 6 def api_key @api_key end |
#api_url ⇒ Object (readonly)
Returns the value of attribute api_url.
6 7 8 |
# File 'lib/gilgamesh.rb', line 6 def api_url @api_url end |
#conn ⇒ Object (readonly)
Returns the value of attribute conn.
6 7 8 |
# File 'lib/gilgamesh.rb', line 6 def conn @conn end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
7 8 9 |
# File 'lib/gilgamesh.rb', line 7 def response @response end |
Instance Method Details
#push(registration_token, title:, body:) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gilgamesh.rb', line 20 def push(registration_token, title:, body:) body = { to: registration_token, notification: { title: title, body: body, icon: 'ic_launcher', click_action: 'android.intent.action.MAIN' } } @response = conn.post do |req| req.headers['Authorization'] = "key=#{api_key}" req.headers['Content-Type'] = 'application/json' req.body = body.to_json end case response.status when 200 "Success" when 400 "INVALID_REGISTRATION: registration_token is not valid" when 401 "Unauthorized: API key is not valid" end end |