Module: Google::Calendar
- Extended by:
- Calendar
- Included in:
- Calendar
- Defined in:
- lib/google/calendar.rb,
lib/google/calendar/event.rb,
lib/google/calendar/errors.rb
Defined Under Namespace
Class Attribute Summary collapse
-
.client_id ⇒ Object
Returns the value of attribute client_id.
-
.id ⇒ Object
Returns the value of attribute id.
Instance Method Summary collapse
- #api ⇒ Object
- #authorize ⇒ Object
- #authorized? ⇒ Boolean
- #client ⇒ Object
-
#execute(api_method, parameters = {}, body = "") ⇒ Object
MEMO : body_objectでなくbodyを使う * 公式のReference的にはbody_object * body_objectを空文字指定でEvent#getすると400 Bad Request * 必要ないときはパラメータに含めない方がよさそう * bodyパラメータなら空文字指定でもOK.
- #secret_key ⇒ Object
- #service_account ⇒ Object
- #signing_key ⇒ Object
Class Attribute Details
.client_id ⇒ Object
Returns the value of attribute client_id.
11 12 13 |
# File 'lib/google/calendar.rb', line 11 def client_id @client_id end |
.id ⇒ Object
Returns the value of attribute id.
11 12 13 |
# File 'lib/google/calendar.rb', line 11 def id @id end |
Instance Method Details
#api ⇒ Object
16 17 18 19 |
# File 'lib/google/calendar.rb', line 16 def api unless client.discovered_api('calendar', 'v3') end |
#authorize ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/google/calendar.rb', line 25 def raise Errno::ENOENT.new(secret_key.path) unless File.exist?(secret_key.path) client. = Signet::OAuth2::Client.new( token_credential_uri: service_account.token_uri, audience: service_account.token_uri, scope: service_account.scope, issuer: service_account.client_email, signing_key: signing_key ) client..fetch_access_token! @authorized = true end |
#authorized? ⇒ Boolean
50 51 52 |
# File 'lib/google/calendar.rb', line 50 def @authorized end |
#client ⇒ Object
21 22 23 |
# File 'lib/google/calendar.rb', line 21 def client @client ||= Google::APIClient.new(:application_name => '') end |
#execute(api_method, parameters = {}, body = "") ⇒ Object
MEMO : body_objectでなくbodyを使う
* 公式のReference的にはbody_object
* body_objectを空文字指定でEvent#getすると400 Bad Request
* 必要ないときはパラメータに含めない方がよさそう
* bodyパラメータなら空文字指定でもOK
59 60 61 62 63 64 65 |
# File 'lib/google/calendar.rb', line 59 def execute(api_method, parameters={}, body="") = { api_method: api_method, parameters: parameters, body: body, headers: { 'Content-Type' => 'application/json' } } client.execute!() end |
#secret_key ⇒ Object
38 39 40 |
# File 'lib/google/calendar.rb', line 38 def secret_key @secret_key ||= Google::SecretKey.new({ path: nil, password: nil }) end |
#service_account ⇒ Object
42 43 44 |
# File 'lib/google/calendar.rb', line 42 def service_account Google::ServiceAccount.new(client_id) end |
#signing_key ⇒ Object
46 47 48 |
# File 'lib/google/calendar.rb', line 46 def signing_key Google::APIClient::KeyUtils.load_from_pkcs12(secret_key.path, secret_key.password) end |