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.
12
13
14
|
# File 'lib/trello/client.rb', line 12
def initialize(attrs = {})
self.configuration.attributes = attrs
end
|
Instance Method Details
#auth_policy ⇒ Object
80
81
82
|
# File 'lib/trello/client.rb', line 80
def auth_policy
@auth_policy ||= auth_policy_class.new(credentials)
end
|
#configuration ⇒ Object
76
77
78
|
# File 'lib/trello/client.rb', line 76
def configuration
@configuration ||= Configuration.new
end
|
72
73
74
|
# File 'lib/trello/client.rb', line 72
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)
65
66
67
68
69
70
|
# File 'lib/trello/client.rb', line 65
def create(path, options)
trello_class = class_from_path(path)
trello_class.save options do |data|
data.client = self
end
end
|
#delete(path) ⇒ Object
32
33
34
35
|
# File 'lib/trello/client.rb', line 32
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")
43
44
45
46
47
48
49
|
# File 'lib/trello/client.rb', line 43
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
52
53
54
55
56
57
|
# File 'lib/trello/client.rb', line 52
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
16
17
18
19
20
|
# File 'lib/trello/client.rb', line 16
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
22
23
24
25
|
# File 'lib/trello/client.rb', line 22
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
27
28
29
30
|
# File 'lib/trello/client.rb', line 27
def put(path, body = {})
uri = Addressable::URI.parse("https://api.trello.com/#{API_VERSION}#{path}")
invoke_verb(:put, uri, body)
end
|