Class: Fulcrum::Client
- Inherits:
-
Object
- Object
- Fulcrum::Client
- Defined in:
- lib/fulcrum/client.rb
Constant Summary collapse
- DEFAULT_URL =
'https://api.fulcrumapp.com/api/v2'
- DEFAULT_USER_AGENT =
"Fulcrum Ruby API Client, Version #{Fulcrum::VERSION}"
Instance Attribute Summary collapse
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#key ⇒ Object
Returns the value of attribute key.
-
#response ⇒ Object
Returns the value of attribute response.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
- .authenticate(username, password, url = DEFAULT_URL) ⇒ Object
- .create_authorization(username, password, organization_id, note, timeout = nil, user_id = nil, url = DEFAULT_URL) ⇒ Object
- .create_connection(url, key = nil) ⇒ Object
- .get_user(username, password, url = DEFAULT_URL) ⇒ Object
Instance Method Summary collapse
- #attachments ⇒ Object
- #audio ⇒ Object
- #audit_logs ⇒ Object
- #authorizations ⇒ Object
- #call(method = :get, path = '', params = {}) ⇒ Object
- #changesets ⇒ Object
- #choice_lists ⇒ Object
- #classification_sets ⇒ Object
- #forms ⇒ Object
-
#initialize(key = nil, url = nil) ⇒ Client
constructor
A new instance of Client.
- #layers ⇒ Object
- #memberships ⇒ Object
- #photos ⇒ Object
- #projects ⇒ Object
- #query(sql, format = 'json') ⇒ Object
- #records ⇒ Object
- #reset ⇒ Object
- #roles ⇒ Object
- #signatures ⇒ Object
- #videos ⇒ Object
- #webhooks ⇒ Object
Constructor Details
#initialize(key = nil, url = nil) ⇒ Client
Returns a new instance of Client.
17 18 19 20 |
# File 'lib/fulcrum/client.rb', line 17 def initialize(key = nil, url = nil) self.key = key self.url = url || DEFAULT_URL end |
Instance Attribute Details
#connection ⇒ Object
Returns the value of attribute connection.
12 13 14 |
# File 'lib/fulcrum/client.rb', line 12 def connection @connection end |
#key ⇒ Object
Returns the value of attribute key.
14 15 16 |
# File 'lib/fulcrum/client.rb', line 14 def key @key end |
#response ⇒ Object
Returns the value of attribute response.
13 14 15 |
# File 'lib/fulcrum/client.rb', line 13 def response @response end |
#url ⇒ Object
Returns the value of attribute url.
15 16 17 |
# File 'lib/fulcrum/client.rb', line 15 def url @url end |
Class Method Details
.authenticate(username, password, url = DEFAULT_URL) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fulcrum/client.rb', line 46 def self.authenticate(username, password, url=DEFAULT_URL) connection = create_connection(url) connection.basic_auth(username, password) resp = connection.get('users.json') resp.body['user']['contexts'].map do |context| { id: context['id'], name: context['name'] } end end |
.create_authorization(username, password, organization_id, note, timeout = nil, user_id = nil, url = DEFAULT_URL) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/fulcrum/client.rb', line 71 def self.(username, password, organization_id, note, timeout = nil, user_id = nil, url=DEFAULT_URL) connection = create_connection(url) connection.basic_auth(username, password) body = { authorization: { organization_id: organization_id, note: note, timeout: timeout, user_id: user_id } } resp = connection.post('authorizations.json', body) resp.body['authorization'] end |
.create_connection(url, key = nil) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/fulcrum/client.rb', line 83 def self.create_connection(url, key = nil) Faraday.new(url) do |connection| connection.request :multipart connection.request :json connection.response :raise_error connection.response :json, content_type: 'application/json' connection.adapter Faraday.default_adapter connection.headers['X-ApiToken'] = key if key connection.headers['X-Require-Media'] = 'false' connection.headers['User-Agent'] = DEFAULT_USER_AGENT end end |
.get_user(username, password, url = DEFAULT_URL) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fulcrum/client.rb', line 59 def self.get_user(username, password, url=DEFAULT_URL) connection = create_connection(url) connection.basic_auth(username, password) resp = connection.get('users.json') user = resp.body['user'] user['contexts'] = user['contexts'].map{|c| c.except!('api_token')} user end |
Instance Method Details
#attachments ⇒ Object
123 124 125 |
# File 'lib/fulcrum/client.rb', line 123 def @attachment ||= Fulcrum::Attachment.new(self) end |
#audio ⇒ Object
119 120 121 |
# File 'lib/fulcrum/client.rb', line 119 def audio @audio ||= Fulcrum::Audio.new(self) end |
#audit_logs ⇒ Object
159 160 161 |
# File 'lib/fulcrum/client.rb', line 159 def audit_logs @audit_logs ||= Fulcrum::AuditLog.new(self) end |
#authorizations ⇒ Object
163 164 165 |
# File 'lib/fulcrum/client.rb', line 163 def @authorizations ||= Fulcrum::Authorization.new(self) end |
#call(method = :get, path = '', params = {}) ⇒ Object
37 38 39 40 |
# File 'lib/fulcrum/client.rb', line 37 def call(method = :get, path = '', params = {}) @response = connection.send(method.to_sym, path, params.with_indifferent_access) @response.body end |
#changesets ⇒ Object
147 148 149 |
# File 'lib/fulcrum/client.rb', line 147 def changesets @changesets ||= Fulcrum::Changeset.new(self) end |
#choice_lists ⇒ Object
99 100 101 |
# File 'lib/fulcrum/client.rb', line 99 def choice_lists @choice_lists ||= Fulcrum::ChoiceList.new(self) end |
#classification_sets ⇒ Object
103 104 105 |
# File 'lib/fulcrum/client.rb', line 103 def classification_sets @classification_sets ||= Fulcrum::ClassificationSet.new(self) end |
#forms ⇒ Object
107 108 109 |
# File 'lib/fulcrum/client.rb', line 107 def forms @forms ||= Fulcrum::Form.new(self) end |
#layers ⇒ Object
143 144 145 |
# File 'lib/fulcrum/client.rb', line 143 def layers @layers ||= Fulcrum::Layer.new(self) end |
#memberships ⇒ Object
139 140 141 |
# File 'lib/fulcrum/client.rb', line 139 def memberships @memberships ||= Fulcrum::Membership.new(self) end |
#photos ⇒ Object
111 112 113 |
# File 'lib/fulcrum/client.rb', line 111 def photos @photos ||= Fulcrum::Photo.new(self) end |
#projects ⇒ Object
131 132 133 |
# File 'lib/fulcrum/client.rb', line 131 def projects @projects ||= Fulcrum::Project.new(self) end |
#query(sql, format = 'json') ⇒ Object
167 168 169 170 171 |
# File 'lib/fulcrum/client.rb', line 167 def query(sql, format = 'json') body = { q: sql, format: format } call(:post, 'query', body) end |
#records ⇒ Object
135 136 137 |
# File 'lib/fulcrum/client.rb', line 135 def records @records ||= Fulcrum::Record.new(self) end |
#reset ⇒ Object
32 33 34 35 |
# File 'lib/fulcrum/client.rb', line 32 def reset @response = nil @connection = nil end |
#roles ⇒ Object
155 156 157 |
# File 'lib/fulcrum/client.rb', line 155 def roles @roles ||= Fulcrum::Role.new(self) end |
#signatures ⇒ Object
127 128 129 |
# File 'lib/fulcrum/client.rb', line 127 def signatures @signatures ||= Fulcrum::Signature.new(self) end |