Class: Trello::Client
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Includes:
- Authorization
- Defined in:
- lib/trello/client.rb
Constant Summary
Authorization::AuthPolicy
Instance Method Summary
collapse
Constructor Details
#initialize(attrs = {}) ⇒ Client
Returns a new instance of Client.
11
12
13
|
# File 'lib/trello/client.rb', line 11
def initialize(attrs = {})
self.configuration.attributes = attrs
end
|
Instance Method Details
#auth_policy ⇒ Object
79
80
81
|
# File 'lib/trello/client.rb', line 79
def auth_policy
@auth_policy ||= auth_policy_class.new(credentials)
end
|
#configuration ⇒ Object
75
76
77
|
# File 'lib/trello/client.rb', line 75
def configuration
@configuration ||= Configuration.new
end
|
71
72
73
|
# File 'lib/trello/client.rb', line 71
def configure
yield configuration if block_given?
end
|
#create(path, options) ⇒ Object
Creates resource with given options (attributes)
Examples:
client.create(:member, options)
client.create(:board, options)
64
65
66
67
68
69
|
# File 'lib/trello/client.rb', line 64
def create(path, options)
trello_class = class_from_path(path)
trello_class.save options do |data|
data.client = self
end
end
|
#delete(path) ⇒ Object
31
32
33
34
|
# File 'lib/trello/client.rb', line 31
def delete(path)
uri = Addressable::URI.parse("https://api.trello.com/#{API_VERSION}#{path}")
invoke_verb(:delete, uri)
end
|
#find(path, id, params = {}) ⇒ Object
Finds given resource by id
Examples:
client.find(:board, "board1234")
client.find(:member, "user1234")
42
43
44
45
46
47
48
|
# File 'lib/trello/client.rb', line 42
def find(path, id, params = {})
response = get("/#{path.to_s.pluralize}/#{id}", params)
trello_class = class_from_path(path)
trello_class.parse response do |data|
data.client = self
end
end
|
#find_many(trello_class, path, params = {}) ⇒ Object
Finds given resource by path with params
51
52
53
54
55
56
|
# File 'lib/trello/client.rb', line 51
def find_many(trello_class, path, params = {})
response = get(path, params)
trello_class.parse_many response do |data|
data.client = self
end
end
|
#get(path, params = {}) ⇒ Object
15
16
17
18
19
|
# File 'lib/trello/client.rb', line 15
def get(path, params = {})
uri = Addressable::URI.parse("https://api.trello.com/#{API_VERSION}#{path}")
uri.query_values = params unless params.empty?
invoke_verb(:get, uri)
end
|
#post(path, body = {}) ⇒ Object
21
22
23
24
|
# File 'lib/trello/client.rb', line 21
def post(path, body = {})
uri = Addressable::URI.parse("https://api.trello.com/#{API_VERSION}#{path}")
invoke_verb(:post, uri, body)
end
|
#put(path, body = {}) ⇒ Object
26
27
28
29
|
# File 'lib/trello/client.rb', line 26
def put(path, body = {})
uri = Addressable::URI.parse("https://api.trello.com/#{API_VERSION}#{path}")
invoke_verb(:put, uri, body)
end
|