Module: TeamSnap
- Defined in:
- lib/teamsnap.rb,
lib/teamsnap/api.rb,
lib/teamsnap/item.rb,
lib/teamsnap/client.rb,
lib/teamsnap/version.rb,
lib/teamsnap/response.rb,
lib/teamsnap/structure.rb,
lib/teamsnap/collection.rb,
lib/teamsnap/auth_middleware.rb
Defined Under Namespace
Modules: Collection, Item Classes: Api, AuthMiddleware, Client, Response, Structure
Constant Summary collapse
- EXCLUDED_RELS =
%w(me apiv2_root root self dude sweet random xyzzy schemas authorization authorization_root plans_all tsl_photos authorization_magic_links authorization_password_resets authorization_tokens authorization_user_registrations authorization_user_registration_initializations authorization_users card_feed)- DEFAULT_URL =
"https://apiv3.teamsnap.com"- Error =
Class.new(StandardError)
- NotFound =
Class.new(TeamSnap::Error)
- InitializationError =
Class.new(TeamSnap::Error)
- VERSION =
"3.0.1"
Class Attribute Summary collapse
-
.client_id ⇒ Object
Returns the value of attribute client_id.
-
.client_secret ⇒ Object
Returns the value of attribute client_secret.
-
.headers ⇒ Object
Returns the value of attribute headers.
-
.root_client ⇒ Object
Returns the value of attribute root_client.
-
.token ⇒ Object
Returns the value of attribute token.
-
.url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .client_send(client, via, href, args) ⇒ Object
- .default_timeout_error ⇒ Object
- .init(opts = {}) ⇒ Object
- .run(client, via, href, args = {}, &block) ⇒ Object
Class Attribute Details
.client_id ⇒ Object
Returns the value of attribute client_id.
25 26 27 |
# File 'lib/teamsnap.rb', line 25 def client_id @client_id end |
.client_secret ⇒ Object
Returns the value of attribute client_secret.
25 26 27 |
# File 'lib/teamsnap.rb', line 25 def client_secret @client_secret end |
.headers ⇒ Object
Returns the value of attribute headers.
25 26 27 |
# File 'lib/teamsnap.rb', line 25 def headers @headers end |
.root_client ⇒ Object
Returns the value of attribute root_client.
25 26 27 |
# File 'lib/teamsnap.rb', line 25 def root_client @root_client end |
.token ⇒ Object
Returns the value of attribute token.
25 26 27 |
# File 'lib/teamsnap.rb', line 25 def token @token end |
.url ⇒ Object
Returns the value of attribute url.
25 26 27 |
# File 'lib/teamsnap.rb', line 25 def url @url end |
Class Method Details
.client_send(client, via, href, args) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/teamsnap.rb', line 77 def client_send(client, via, href, args) case via when :get, :delete client.send(via, href.gsub("/v3", ""), args) when :patch, :post client.send(via, href.gsub("/v3", "")) do |req| if use_multipart?(args) req.body = args else req.body = JSON.generate(args) end end else raise TeamSnap::Error.new("Don't know how to run `#{via}`") end end |
.default_timeout_error ⇒ Object
70 71 72 73 74 75 |
# File 'lib/teamsnap.rb', line 70 def default_timeout_error -> { warn("Connection to API failed with TimeoutError") {:links => []} } end |
.init(opts = {}) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/teamsnap.rb', line 28 def init(opts = {}) unless opts[:token] || (opts[:client_id] && opts[:client_secret]) raise ArgumentError.new("You must provide a :token or :client_id and :client_secret pair to '.init'") end ## setup variables required self.client_id = opts.fetch(:client_id) {} self.client_secret = opts.fetch(:client_secret) {} self.token = opts.fetch(:token) {} self.url = opts.fetch(:url) { DEFAULT_URL } ## create universally accessible TeamSnap.root_client self.root_client = TeamSnap::Client.new(:token => token) ## include any feature headers if opts[:headers] if headers = opts.fetch(:headers) self.root_client.headers = self.root_client.headers.merge(headers) end end ## Make the apiv3 root call. collection is parsed JSON collection = TeamSnap.run(root_client, :get, self.url, {}) do self.root_client = nil raise TeamSnap::InitializationError end ## Setup Dynamic Classes from the collection TeamSnap::Structure.init(root_client, collection) ## Queries and Commands parsing for shortcut methods TeamSnap::Collection.apply_endpoints(self, collection) && true end |
.run(client, via, href, args = {}, &block) ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/teamsnap.rb', line 62 def run(client, via, href, args = {}, &block) timeout_error = block || default_timeout_error resp = client_send(client, via, href, args) return TeamSnap::Response.load_collection(resp) rescue Faraday::TimeoutError timeout_error.call end |