Class: Totter::Client

Inherits:
Object
  • Object
show all
Includes:
Activities, Async, Avatars, Choices, Comments, Configuration, Connections, Decisions, Slugs, Stickers, Timelines, Users, Votes
Defined in:
lib/totter/client.rb,
lib/totter/client/async.rb,
lib/totter/client/slugs.rb,
lib/totter/client/users.rb,
lib/totter/client/votes.rb,
lib/totter/client/avatars.rb,
lib/totter/client/choices.rb,
lib/totter/client/comments.rb,
lib/totter/client/stickers.rb,
lib/totter/client/decisions.rb,
lib/totter/client/timelines.rb,
lib/totter/client/activities.rb,
lib/totter/client/connections.rb,
lib/totter/client/configuration.rb

Overview

API client for interacting with the Seesaw API

Defined Under Namespace

Modules: Activities, Async, Avatars, Choices, Comments, Configuration, Connections, Decisions, Slugs, Stickers, Timelines, Users, Votes

Constant Summary collapse

DEFAULTS =

Default parameters for the client

{
  :api_scheme => 'https',
  :api_host => 'api.seesaw.co',
  :api_version => '1',
  :result_format => :mashie,
  :transport => :http
}

Constants included from Timelines

Timelines::DEFAULT_TIMELINE_OPTIONS

Constants included from Activities

Activities::DEFAULT_ACTIVITY_OPTIONS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Votes

#create_vote

Methods included from Users

#follow, #followers, #following, #me, #unfollow, #update_me, #user, #votes

Methods included from Timelines

#flagged_timeline, #friends_timeline, #global_timeline, #hashtag_timeline, #random_timeline_decision, #search_timeline, #sticker_timeline, #user_timeline

Methods included from Stickers

#follow_sticker, #sticker

Methods included from Slugs

#slug

Methods included from Decisions

#clone_decision, #create_decision, #decision, #decision_analytics, #destroy_decision, #flag_decision, #publish_decision, #unflag_decision

Methods included from Connections

#connections, #find_connection_friends

Methods included from Configuration

#configuration, #explore

Methods included from Comments

#comments, #create_comment, #destroy_comment

Methods included from Choices

#choice, #choice_votes, #create_choice_for_image, #create_choice_upload, #crop_choice, #destroy_choice

Methods included from Avatars

#avatar, #avatars, #create_avatar, #destroy_avatar

Methods included from Async

#async_result

Methods included from Activities

#activities, #friends_activities, #my_activities

Constructor Details

#initialize(options = {}) ⇒ Client

Initialize a new client.

Parameters:

  • options (Hash) (defaults to: {})

    optionally specify ‘:access_token`, `:api_scheme`, `:api_host`, ’:api_url’, ‘:api_version`, `:client_token`, or `:transport`.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/totter/client.rb', line 57

def initialize(options = {})
  options = { :access_token => options } if options.is_a? String
  options = self.class.options.merge(options)

  # Parse `api_url` option
  if url = options.delete(:api_url)
    uri = URI.parse(url)
    options[:api_scheme] = uri.scheme
    options[:api_host] = uri.host + (uri.port != 80 && uri.port != 443 ? ":#{uri.port}" : '')
  end

  @access_token = options[:access_token] if options[:access_token]
  @api_scheme = options[:api_scheme]
  @api_host = options[:api_host]
  @api_version = options[:api_version]
  @client_token = options[:client_token] if options[:client_token]
  @transport = options[:transport]
  @result_format = options[:result_format]

  # Include transport
  transport_module = Totter::Transport::TRANSPORT_MAP[@transport]
  raise 'Invalid transport' unless transport_module
  self.extend transport_module
end

Instance Attribute Details

#access_tokenObject (readonly)

Returns the value of attribute access_token.



23
24
25
# File 'lib/totter/client.rb', line 23

def access_token
  @access_token
end

#api_hostObject (readonly)

Returns the value of attribute api_host.



25
26
27
# File 'lib/totter/client.rb', line 25

def api_host
  @api_host
end

#api_schemeObject (readonly)

Returns the value of attribute api_scheme.



24
25
26
# File 'lib/totter/client.rb', line 24

def api_scheme
  @api_scheme
end

#api_versionObject (readonly)

Returns the value of attribute api_version.



26
27
28
# File 'lib/totter/client.rb', line 26

def api_version
  @api_version
end

#result_formatObject (readonly)

Returns the value of attribute result_format.



28
29
30
# File 'lib/totter/client.rb', line 28

def result_format
  @result_format
end

#transportObject (readonly)

Returns the value of attribute transport.



27
28
29
# File 'lib/totter/client.rb', line 27

def transport
  @transport
end

Class Method Details

.configure {|options| ... } ⇒ Object

Allows the setting of configuration parameters in a configure block.

Yields:



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

def self.configure
  yield options
end

.optionsObject

The current configuration parameters for all clients



40
41
42
# File 'lib/totter/client.rb', line 40

def self.options
  @options ||= Hashie::Mash.new(DEFAULTS.dup)
end

.options=(val) ⇒ Object

Sets the current configuration parameters for all clients



45
46
47
# File 'lib/totter/client.rb', line 45

def self.options=(val)
  @options = val
end

.stubbed?Boolean

Returns the current status of HTTP stubbing

Returns:

  • (Boolean)


104
105
106
# File 'lib/totter/client.rb', line 104

def self.stubbed?
  @@stubbed
end

Instance Method Details

#authenticated?Boolean

Is the client has an access token.

Returns:

  • (Boolean)

    true if it is using one and false if it is not



92
93
94
# File 'lib/totter/client.rb', line 92

def authenticated?
  @access_token != nil and @access_token.length > 0
end

#base_urlString

API base URL.

Returns:

  • (String)

    API base URL



85
86
87
# File 'lib/totter/client.rb', line 85

def base_url
  "#{@api_scheme}://#{@api_host}/v#{@api_version}/"
end

#ssl?Boolean

Is the client using SSL.

Returns:

  • (Boolean)

    true if it is using SSL and false if it is not



99
100
101
# File 'lib/totter/client.rb', line 99

def ssl?
  @api_scheme == 'https'
end