Module: Playapi::Configurable

Extended by:
Forwardable
Included in:
Playapi, Client
Defined in:
lib/playapi/configurable.rb

Constant Summary collapse

DEFAULT_CONNECTION_MIDDLEWARE =
[
  Faraday::Request::Multipart,
  Faraday::Request::UrlEncoded,
  FaradayMiddleware::ParseJson
]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client_id=(value) ⇒ Object (writeonly)

Sets the attribute client_id

Parameters:

  • value

    the value to set the attribute client_id to.



4
5
6
# File 'lib/playapi/configurable.rb', line 4

def client_id=(value)
  @client_id = value
end

#client_secret=(value) ⇒ Object (writeonly)

Sets the attribute client_secret

Parameters:

  • value

    the value to set the attribute client_secret to.



4
5
6
# File 'lib/playapi/configurable.rb', line 4

def client_secret=(value)
  @client_secret = value
end

#connection_middlewareObject

Returns the value of attribute connection_middleware.



5
6
7
# File 'lib/playapi/configurable.rb', line 5

def connection_middleware
  @connection_middleware
end

#connection_optionsObject

Returns the value of attribute connection_options.



5
6
7
# File 'lib/playapi/configurable.rb', line 5

def connection_options
  @connection_options
end

#endpointObject

Returns the value of attribute endpoint.



5
6
7
# File 'lib/playapi/configurable.rb', line 5

def endpoint
  @endpoint
end

#identity_mapObject

Returns the value of attribute identity_map.



5
6
7
# File 'lib/playapi/configurable.rb', line 5

def identity_map
  @identity_map
end

#oauth_token=(value) ⇒ Object (writeonly)

Sets the attribute oauth_token

Parameters:

  • value

    the value to set the attribute oauth_token to.



4
5
6
# File 'lib/playapi/configurable.rb', line 4

def oauth_token=(value)
  @oauth_token = value
end

Class Method Details

.keysObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/playapi/configurable.rb', line 17

def keys
  @keys ||= [
    :client_id,
    :client_secret,
    :oauth_token,
    :endpoint,
    :token_secret,
    :connection_options,
    :identity_map,
    :connection_middleware,
  ]
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:

Raises:

  • (Twitter::Error::ConfigurationError)

    Error is raised when supplied twitter credentials are not a String or Symbol.



36
37
38
39
40
# File 'lib/playapi/configurable.rb', line 36

def configure
  yield self
  validate_credential_type!
  self
end

#credentials?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/playapi/configurable.rb', line 43

def credentials?
  credentials.values.all?
end

#reset!Object Also known as: setup



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/playapi/configurable.rb', line 47

def reset!
  defaultz = {client_id: "F1Ox4PEhf1eiNGRge7kscIRgay1mh8cbi2zruIC1OI", client_secret: "xLeR0lXVdEtfjwP04w4FJKZm8KxS97Qg5o8Xbyw3JeE", oauth_token: "KqoCXCoyhrJTyGFtCYmiUcWModkTYBILiMHyKGQCBYg", token_secret: "b63V8SyY9ip8yigE5o6bsf3HFyza1wRfLnl3HyhhPz4", endpoint: "http://api.papi.io/"}
  # we can probably chuck conn_ops
  conn_ops = {
    :connection_options => {:headers => {:accept => "application/json", :user_agent => "PlayAPI Gem 0.1.1"}, 
      :ssl => {:verify => false}}
  }
  #defaultz.merge!(conn_ops)

  defaultz.merge!(:connection_middleware => DEFAULT_CONNECTION_MIDDLEWARE)

  Playapi::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", defaultz[key])
  end
  self
end