Class: Croudia::Client

Instance Method Summary collapse

Methods included from Rest::Users

#user, #users

Methods included from Rest::Trends

#place

Methods included from Rest::Statuses

#comment, #comment_with_media, #delete_status, #home_timeline, #mentions_timeline, #public_timeline, #spread, #status, #update_status, #update_status_with_media, #user_timeline

Methods included from Rest::SecretMails

#delete_message, #message, #message_photo, #new_message, #new_message_with_media, #received, #sent

Methods included from Rest::Search

#search_favorites, #search_statuses, #search_users, #search_users_by_profile

Methods included from Rest::OAuth

#authorize_url, #refresh, #token

Methods included from Rest::Mutes::Users

#mute, #mute_ids, #mutes, #umnute

Methods included from Rest::Friends

#friend_ids, #friends

Methods included from Rest::FriendShips

#follow, #relationship, #relationships, #unfollow

Methods included from Rest::Followers

#follower_ids, #followers

Methods included from Rest::Favorites

#favorite, #favorites, #unfavorite

Methods included from Rest::Blocks

#block, #block_ids, #blocks, #unblock

Methods included from Rest::Account

#update_cover_image, #update_profile, #update_profile_image, #verify_credentials

Constructor Details

#initialize(params = {}) ⇒ Croudia::Client

Initializes a new Client object

Parameters:

  • options (Hash)


41
42
43
44
45
# File 'lib/croudia/client.rb', line 41

def initialize(params = {})
  params.each do |key, value|
    instance_variable_set("@#{key}", value)
  end   
end

Instance Method Details

#get(endpoint, params = {}) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/croudia/client.rb', line 54

def get(endpoint, params = {})
  request = Typhoeus::Request.new(
    "https://api.croudia.com/#{endpoint}",
    method: :get,
    params: params,
    headers: {Authorization: "Bearer #{@access_token}"}
  )
  request.run
  response = request.response
    
  if(response.code != 200)
    raise Croudia::Error.from_response(response)
  end
  JSON.parse(response.body)
end

#post(endpoint, params = {}) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/croudia/client.rb', line 70

def post(endpoint, params = {})
  request = Typhoeus::Request.new(
    "https://api.croudia.com/#{endpoint}",
    method: :post,
    body: params,
    headers: {Authorization: "Bearer #{@access_token}"}
  )
  request.run
  response = request.response

  if(response.code != 200)
    raise Croudia::Error.from_response(response)
  end
  JSON.parse(response.body)
end

#update_access_token!(access_token) ⇒ Object

Updates access token.

Parameters:

  • access_token (String)

    Access token.



50
51
52
# File 'lib/croudia/client.rb', line 50

def update_access_token!(access_token)
  @access_token = access_token
end