Class: Lapse::Client

Inherits:
Object
  • Object
show all
Includes:
Clips, Configuration, Frames, GlobalTimelines, UserTimelines, Users
Defined in:
lib/lapse/client.rb,
lib/lapse/client/clips.rb,
lib/lapse/client/likes.rb,
lib/lapse/client/users.rb,
lib/lapse/client/frames.rb,
lib/lapse/client/configuration.rb,
lib/lapse/client/user_timelines.rb,
lib/lapse/client/global_timelines.rb

Overview

API client for interacting with the Seesaw API

Defined Under Namespace

Modules: Clips, Configuration, Frames, GlobalTimelines, Likes, UserTimelines, Users

Constant Summary collapse

DEFAULTS =

Default parameters for the client

{
  :api_scheme => 'https',
  :api_host => 'everlapse.com',
  :api_version => '1',
  :api_prefix => 'api',
  :result_format => :mashie,
  :transport => :http
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from UserTimelines

#user_contributed_timeline, #user_likes_timeline, #user_timeline

Methods included from Users

#authenticate, #badges, #block, #follow, #followers, #following, #me, #unfollow, #update_me, #user

Methods included from GlobalTimelines

#featured_timeline, #global_timeline

Methods included from Frames

#create_frame, #crop_frame, #destroy_frame

Methods included from Configuration

#configuration, #explore

Methods included from Clips

#all_clips, #clip, #create_clip, #destroy_clip, #featured_clips, #flag_clip, #modify_frames, #publish_clip, #submit_frames, #unflag_clip, #update_clip

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`.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/lapse/client.rb', line 52

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]
  @api_prefix = options[:api_prefix]
  @client_token = options[:client_token] if options[:client_token]
  @transport = options[:transport]
  @result_format = options[:result_format]

  # Include transport
  transport_module = Lapse::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.



16
17
18
# File 'lib/lapse/client.rb', line 16

def access_token
  @access_token
end

#api_hostObject (readonly)

Returns the value of attribute api_host.



18
19
20
# File 'lib/lapse/client.rb', line 18

def api_host
  @api_host
end

#api_prefixObject (readonly)

Returns the value of attribute api_prefix.



19
20
21
# File 'lib/lapse/client.rb', line 19

def api_prefix
  @api_prefix
end

#api_schemeObject (readonly)

Returns the value of attribute api_scheme.



17
18
19
# File 'lib/lapse/client.rb', line 17

def api_scheme
  @api_scheme
end

#api_versionObject (readonly)

Returns the value of attribute api_version.



20
21
22
# File 'lib/lapse/client.rb', line 20

def api_version
  @api_version
end

#result_formatObject (readonly)

Returns the value of attribute result_format.



22
23
24
# File 'lib/lapse/client.rb', line 22

def result_format
  @result_format
end

#transportObject (readonly)

Returns the value of attribute transport.



21
22
23
# File 'lib/lapse/client.rb', line 21

def transport
  @transport
end

Class Method Details

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

Allows the setting of configuration parameters in a configure block.

Yields:



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

def self.configure
  yield options
end

.optionsObject

The current configuration parameters for all clients



35
36
37
# File 'lib/lapse/client.rb', line 35

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

.options=(val) ⇒ Object

Sets the current configuration parameters for all clients



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

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

.stubbed?Boolean

Returns the current status of HTTP stubbing

Returns:

  • (Boolean)


100
101
102
# File 'lib/lapse/client.rb', line 100

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



88
89
90
# File 'lib/lapse/client.rb', line 88

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

#base_urlString

API base URL.

Returns:

  • (String)

    API base URL



81
82
83
# File 'lib/lapse/client.rb', line 81

def base_url
  "#{@api_scheme}://#{@api_host}/#{@api_prefix}/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



95
96
97
# File 'lib/lapse/client.rb', line 95

def ssl?
  @api_scheme == 'https'
end