Class: Kippt::Client

Inherits:
Object
  • Object
show all
Includes:
Connection
Defined in:
lib/kippt/client.rb

Constant Summary

Constants included from Connection

Kippt::Connection::HOST

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Connection

#delete, #get, #post, #put

Constructor Details

#initialize(options = {}) ⇒ Client

Returns a new instance of Client.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/kippt/client.rb', line 11

def initialize(options = {})
  self.debug = options.fetch(:debug, nil)

  if options[:unauthenticated]
    # Unauthenticated
  else
    @username  = options.fetch(:username) { raise ArgumentError.new("username is required") }

    @password  = options.fetch(:password) { nil }
    @token     = options.fetch(:token) { nil }

    if @password.nil? && @token.nil?
      raise ArgumentError.new("password or token is required")
    end
  end
end

Instance Attribute Details

#passwordObject (readonly)

Returns the value of attribute password.



9
10
11
# File 'lib/kippt/client.rb', line 9

def password
  @password
end

#tokenObject (readonly)

Returns the value of attribute token.



9
10
11
# File 'lib/kippt/client.rb', line 9

def token
  @token
end

#usernameObject (readonly)

Returns the value of attribute username.



9
10
11
# File 'lib/kippt/client.rb', line 9

def username
  @username
end

Instance Method Details

#account(include_api_token = false) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/kippt/client.rb', line 41

def (include_api_token = false)
  if include_api_token
    url = "account?include_data=api_token"
  else
    url = "account"
  end
  Kippt::User.new(get(url).body, self)
end

#clipsObject



54
55
56
# File 'lib/kippt/client.rb', line 54

def clips
  Kippt::RootClips.new(self)
end

#collection_resource_for(resource_class, *options) ⇒ Object



62
63
64
# File 'lib/kippt/client.rb', line 62

def collection_resource_for(resource_class, *options)
  resource_class.new(*([self] + options))
end

#debugObject Also known as: debug?



32
33
34
35
36
37
38
# File 'lib/kippt/client.rb', line 32

def debug
  if @debug.nil?
    !!ENV["DEBUG"]
  else
    @debug
  end
end

#debug=(value) ⇒ Object



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

def debug=(value)
  @debug = value
end

#listsObject



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

def lists
  Kippt::Lists.new(self)
end

#resource_from_url(resource_class, url) ⇒ Object

Raises:

  • (ArgumentError)


66
67
68
69
70
# File 'lib/kippt/client.rb', line 66

def resource_from_url(resource_class, url)
  raise ArgumentError.new("The parameter URL can't be blank") if url.nil? || url == ""

  resource_class.new(self.get(url).body, self)
end

#usersObject



58
59
60
# File 'lib/kippt/client.rb', line 58

def users
  Kippt::Users.new(self)
end