Created
April 19, 2012 19:43
-
-
Save kerinin/2423634 to your computer and use it in GitHub Desktop.
Context.io account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Account < ActiveRecord::Base | |
[ | |
:discovery, | |
:list_connect_tokens, | |
:get_connect_token, | |
:add_connect_token, | |
:delete_connect_token, | |
:list_oauth_providers, | |
:get_oauth_provider, | |
:add_oauth_provider, | |
:delete_oauth_provider, | |
:add_account, | |
:modify_account, | |
:get_account, | |
:delete_account | |
].each do |method| | |
send :define_method, method do |args| | |
args ||= {} | |
handle_response cio_connection.send(method, args) | |
end | |
end | |
[ | |
:list_contacts, | |
:get_contact, | |
:list_contact_files, | |
:list_contact_messages, | |
:list_contact_threads, | |
:list_files, | |
:get_file, | |
:get_file_content, | |
:get_file_changes, | |
:list_file_revisions, | |
:list_file_related, | |
:list_messages, | |
:get_message, | |
:get_message_headers, | |
:get_message_flags, | |
:get_message_body, | |
:get_message_thread, | |
:list_threads, | |
:get_thread, | |
:list_account_email_addresses, | |
:delete_email_address_from_account, | |
:set_primary_email_address_for_account, | |
:add_email_address_to_account, | |
:modify_source, | |
:reset_source_status, | |
:list_sources, | |
:get_source, | |
:add_source, | |
:delete_source, | |
:sync_source, | |
:get_sync, | |
:add_folder_to_source, | |
:list_source_folders, | |
:list_webhooks, | |
:get_webhook, | |
:add_webhook, | |
:delete_webhook | |
].each do |method| | |
send(:define_method, method) do |args| | |
args ||= {} | |
handle_response cio_connection.send(method, {:account => account_id}.merge(args)) | |
end | |
end | |
def handle_response(response) | |
case response.code | |
when '200' | |
JSON.parse( response.body ) | |
when '500' | |
raise Exceptions::Response500 | |
else | |
raise "problem with response, code: #{response.code}" | |
end | |
end | |
def cio_connection | |
@cio_connection ||= ContextIO::Connection.new(api_key, api_secret) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment