Class: Breacan::Client
- Inherits:
-
Object
- Object
- Breacan::Client
- Includes:
- Authentication, Api, Auth, Channels, Chat, Emoji, Files, Groups, Im, OAuth, Rtm, Search, Star, Usergroups, Users, Configurable
- Defined in:
- lib/breacan/client.rb,
lib/breacan/client/im.rb,
lib/breacan/client/api.rb,
lib/breacan/client/rtm.rb,
lib/breacan/client/auth.rb,
lib/breacan/client/chat.rb,
lib/breacan/client/star.rb,
lib/breacan/client/emoji.rb,
lib/breacan/client/files.rb,
lib/breacan/client/oauth.rb,
lib/breacan/client/users.rb,
lib/breacan/client/groups.rb,
lib/breacan/client/search.rb,
lib/breacan/client/channels.rb,
lib/breacan/client/usergroups.rb
Defined Under Namespace
Modules: Api, Auth, Channels, Chat, Emoji, Files, Groups, Im, OAuth, Rtm, Search, Star, Usergroups, Users
Constant Summary collapse
- CONVENIENCE_HEADERS =
Set.new(i(accept content_type))
Constants included from Configurable
Breacan::Configurable::OPTIONS_KEYS
Instance Method Summary collapse
- #agent ⇒ Object
- #delete(url, options = {}) ⇒ Object
- #get(url, options = {}) ⇒ Object
- #get_with_auto_paginate(url, options = {}) ⇒ Object
- #head(url, options = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Client
constructor
A new instance of Client.
- #patch(url, options = {}) ⇒ Object
- #post(url, options = {}) ⇒ Object
- #put(url, options = {}) ⇒ Object
- #same_options?(opts) ⇒ Boolean
Methods included from Usergroups
#usergroups_create, #usergroups_disable, #usergroups_enable, #usergroups_list, #usergroups_update, #usergroups_users_list, #usergroups_users_update
Methods included from Users
#user_by_name, #users_get_presence, #users_info, #users_list, #users_set_active, #users_set_presence
Methods included from Star
Methods included from Search
#search_all, #search_files, #search_messages
Methods included from Rtm
Methods included from OAuth
Methods included from Im
#im_close, #im_history, #im_list, #im_mark, #im_open
Methods included from Groups
#groups_archive, #groups_create, #groups_history, #groups_info, #groups_info_by_name, #groups_invite, #groups_join, #groups_kick, #groups_leave, #groups_list, #groups_mark, #groups_rename, #groups_set_purpose, #groups_set_topic, #groups_unarchive
Methods included from Files
#files_delete, #files_info, #files_list, #files_upload, #reset_files_upload_builder, #set_files_upload_builder
Methods included from Emoji
Methods included from Chat
#chat_delete, #chat_post_message, #chat_update
Methods included from Channels
#channel_by_name, #channels_archive, #channels_create, #channels_history, #channels_info, #channels_invite, #channels_join, #channels_kick, #channels_leave, #channels_list, #channels_mark, #channels_rename, #channels_set_purpose, #channels_set_topic, #channels_unarchive
Methods included from Auth
Methods included from Api
Methods included from Configurable
#api_endpoint, #configure, #default_builder, #default_serializer, keys, #options, #reset!, #web_endpoint
Methods included from Authentication
Constructor Details
#initialize(options = {}) ⇒ Client
Returns a new instance of Client.
42 43 44 45 46 |
# File 'lib/breacan/client.rb', line 42 def initialize( = {}) Breacan::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", [key] || Breacan.instance_variable_get(:"@#{key}")) end end |
Instance Method Details
#agent ⇒ Object
115 116 117 118 119 120 |
# File 'lib/breacan/client.rb', line 115 def agent @agent ||= Sawyer::Agent.new(api_endpoint, ) do |http| http.headers[:accept] = media_type http.headers[:user_agent] = user_agent end end |
#delete(url, options = {}) ⇒ Object
107 108 109 |
# File 'lib/breacan/client.rb', line 107 def delete(url, = {}) request :delete, url, end |
#get(url, options = {}) ⇒ Object
52 53 54 55 |
# File 'lib/breacan/client.rb', line 52 def get(url, = {}) return get_with_auto_paginate(url, ) if auto_paginate request :get, url, parse_query_and_convenience_headers() end |
#get_with_auto_paginate(url, options = {}) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/breacan/client.rb', line 57 def get_with_auto_paginate(url, = {}) res = nil if url.end_with?('.list') nextc = nil loop do r = request :get, url, parse_query_and_convenience_headers(.merge({cursor: nextc})) if r.is_a?(Sawyer::Resource) res ||= {} res = res.deep_merge(r) do |key, this_val, other_val| if this_val.is_a?(Array) && other_val.is_a?(Array) this_val + other_val else other_val end end elsif r.is_a?(Array) res ||= [] res.concat(r) else raise "unknown response type" end if r.respond_to?(:response_metadata) if r..next_cursor == "" res = Sawyer::Resource.new(Sawyer::Agent.new(api_endpoint), res) break end nextc = r..next_cursor else break end end else res = request :get, url, parse_query_and_convenience_headers() end res end |
#head(url, options = {}) ⇒ Object
111 112 113 |
# File 'lib/breacan/client.rb', line 111 def head(url, = {}) request :head, url, parse_query_and_convenience_headers() end |
#patch(url, options = {}) ⇒ Object
103 104 105 |
# File 'lib/breacan/client.rb', line 103 def patch(url, = {}) request :patch, url, end |
#post(url, options = {}) ⇒ Object
95 96 97 |
# File 'lib/breacan/client.rb', line 95 def post(url, = {}) request :post, url, end |
#put(url, options = {}) ⇒ Object
99 100 101 |
# File 'lib/breacan/client.rb', line 99 def put(url, = {}) request :put, url, end |
#same_options?(opts) ⇒ Boolean
48 49 50 |
# File 'lib/breacan/client.rb', line 48 def (opts) opts.hash == .hash end |