Class: Yellowant::YellowantObj
- Inherits:
-
Object
- Object
- Yellowant::YellowantObj
- Defined in:
- lib/yellowant/api.rb
Instance Method Summary collapse
- #_get(endpoint, data = {}) ⇒ Object
- #_get_errors(response) ⇒ Object
- #_post(endpoint, payload = {}, contentType = 'application/json') ⇒ Object
- #create_user_integration ⇒ Object
- #delete_integrtion(integration_id) ⇒ Object
- #get_access_token(code) ⇒ Object
- #get_user_profile ⇒ Object
-
#initialize(app_key: nil, app_secret: nil, access_token: nil, redirect_uri: nil, token_type: 'bearer', oauth_version: 2, api_version: Yellowant::VERSION, client_args: nil, auth_endpoint: 'authenticate') ⇒ YellowantObj
constructor
attr_accessor :app_key, :app_secret, :access_token, :redirect_uri, :token_type, :oauth_version, :client_args,.
- #send_message(integration_id, message) ⇒ Object
- #send_webhook_message(integration_id, webhook_subscription_id, message) ⇒ Object
Constructor Details
#initialize(app_key: nil, app_secret: nil, access_token: nil, redirect_uri: nil, token_type: 'bearer', oauth_version: 2, api_version: Yellowant::VERSION, client_args: nil, auth_endpoint: 'authenticate') ⇒ YellowantObj
attr_accessor :app_key, :app_secret, :access_token, :redirect_uri, :token_type,
:oauth_version, :client_args,
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/yellowant/api.rb', line 18 def initialize(app_key: nil, app_secret: nil, access_token: nil, redirect_uri: nil, token_type: 'bearer', oauth_version: 2, api_version: Yellowant::VERSION, client_args: nil, auth_endpoint: 'authenticate') local_variables.each do |k| v = eval(k.to_s) instance_variable_set("@#{k}", v) unless v.nil? end @api_url = "https://api.yellowant.com/api/" end |
Instance Method Details
#_get(endpoint, data = {}) ⇒ Object
29 30 31 32 33 |
# File 'lib/yellowant/api.rb', line 29 def _get(endpoint, data={}) body = JSON.generate(data) header = {'Content-type'=> "application/json", "Authorization"=>"Bearer #{@access_token}"} HTTParty.get(@api_url+endpoint, :data=>body, :headers=>header ) end |
#_get_errors(response) ⇒ Object
46 47 |
# File 'lib/yellowant/api.rb', line 46 def _get_errors(response) end |
#_post(endpoint, payload = {}, contentType = 'application/json') ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/yellowant/api.rb', line 35 def _post(endpoint, payload={}, contentType='application/json') header = {'Content-type'=> contentType} if contentType == 'application/x-www-form-urlencoded' payload['access_token'] = @access_token HTTParty.post(@api_url+endpoint, :query=>payload, :headers=>header) else header['Authorization'] = "Bearer #{@access_token}" HTTParty.post(@api_url+endpoint, body: payload.to_json, headers: header) end end |
#create_user_integration ⇒ Object
59 60 61 |
# File 'lib/yellowant/api.rb', line 59 def create_user_integration() _post("user/integration/", payload={}, contentType="application/x-www-form-urlencoded") end |
#delete_integrtion(integration_id) ⇒ Object
78 79 80 81 |
# File 'lib/yellowant/api.rb', line 78 def delete_integrtion(integration_id) header = {'Content-type'=> "application/json", "Authorization"=>"Bearer #{@access_token}"} HTTParty.delete(@api_url+"user/integration/#{integration_id}/", :headers => header) end |
#get_access_token(code) ⇒ Object
49 50 51 52 53 |
# File 'lib/yellowant/api.rb', line 49 def get_access_token(code) data = {'grant_type'=> "authorization_code", 'client_id'=>@app_key, 'client_secret'=> @app_secret, "code"=>code, 'redirect_uri'=>@redirect_uri} _post("oauth2/token/", payload=data, contentType="application/x-www-form-urlencoded") end |
#get_user_profile ⇒ Object
55 56 57 |
# File 'lib/yellowant/api.rb', line 55 def get_user_profile() _get("user/profile") end |
#send_message(integration_id, message) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/yellowant/api.rb', line 63 def (integration_id, ) if .is_a? Messages::MessageClass payload = .get_dict else raise YellowantExceptions::YellowAntError, "message must be 'Messages::MessageClass' class" end payload['requester_application'] = integration_id _post("user/message/", payload=payload) end |
#send_webhook_message(integration_id, webhook_subscription_id, message) ⇒ Object
73 74 75 76 |
# File 'lib/yellowant/api.rb', line 73 def (integration_id, webhook_subscription_id, ) payload = {'webhook_id'=> webhook_subscription_id, 'requester_application'=> integration_id} _post("user/application/webhook/#{webhookSubscriptionId}/", payload = payload.merge()) end |