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.
15 16 17 18 |
# File 'lib/fulcrum/client.rb', line 15 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.
10 11 12 |
# File 'lib/fulcrum/client.rb', line 10 def connection @connection end |
#key ⇒ Object
Returns the value of attribute key.
12 13 14 |
# File 'lib/fulcrum/client.rb', line 12 def key @key end |
#response ⇒ Object
Returns the value of attribute response.
11 12 13 |
# File 'lib/fulcrum/client.rb', line 11 def response @response end |
#url ⇒ Object
Returns the value of attribute url.
13 14 15 |
# File 'lib/fulcrum/client.rb', line 13 def url @url end |
Class Method Details
.authenticate(username, password, url = DEFAULT_URL) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/fulcrum/client.rb', line 44 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
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/fulcrum/client.rb', line 70 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
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/fulcrum/client.rb', line 82 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
57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/fulcrum/client.rb', line 57 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
122 123 124 |
# File 'lib/fulcrum/client.rb', line 122 def ||= Fulcrum::Attachment.new(self) end |
#audio ⇒ Object
118 119 120 |
# File 'lib/fulcrum/client.rb', line 118 def audio @audio ||= Fulcrum::Audio.new(self) end |
#audit_logs ⇒ Object
158 159 160 |
# File 'lib/fulcrum/client.rb', line 158 def audit_logs @audit_logs ||= Fulcrum::AuditLog.new(self) end |
#authorizations ⇒ Object
162 163 164 |
# File 'lib/fulcrum/client.rb', line 162 def ||= Fulcrum::Authorization.new(self) end |
#call(method = :get, path = '', params = {}) ⇒ Object
35 36 37 38 |
# File 'lib/fulcrum/client.rb', line 35 def call(method = :get, path = '', params = {}) @response = connection.send(method.to_sym, path, params.with_indifferent_access) @response.body end |
#changesets ⇒ Object
146 147 148 |
# File 'lib/fulcrum/client.rb', line 146 def changesets @changesets ||= Fulcrum::Changeset.new(self) end |
#choice_lists ⇒ Object
98 99 100 |
# File 'lib/fulcrum/client.rb', line 98 def choice_lists @choice_lists ||= Fulcrum::ChoiceList.new(self) end |
#classification_sets ⇒ Object
102 103 104 |
# File 'lib/fulcrum/client.rb', line 102 def classification_sets @classification_sets ||= Fulcrum::ClassificationSet.new(self) end |
#forms ⇒ Object
106 107 108 |
# File 'lib/fulcrum/client.rb', line 106 def forms @forms ||= Fulcrum::Form.new(self) end |
#layers ⇒ Object
142 143 144 |
# File 'lib/fulcrum/client.rb', line 142 def layers @layers ||= Fulcrum::Layer.new(self) end |
#memberships ⇒ Object
138 139 140 |
# File 'lib/fulcrum/client.rb', line 138 def memberships @memberships ||= Fulcrum::Membership.new(self) end |
#photos ⇒ Object
110 111 112 |
# File 'lib/fulcrum/client.rb', line 110 def photos @photos ||= Fulcrum::Photo.new(self) end |
#projects ⇒ Object
130 131 132 |
# File 'lib/fulcrum/client.rb', line 130 def projects @projects ||= Fulcrum::Project.new(self) end |
#query(sql, format = 'json') ⇒ Object
166 167 168 169 170 |
# File 'lib/fulcrum/client.rb', line 166 def query(sql, format = 'json') body = { q: sql, format: format } call(:post, 'query', body) end |
#records ⇒ Object
134 135 136 |
# File 'lib/fulcrum/client.rb', line 134 def records @records ||= Fulcrum::Record.new(self) end |
#reset ⇒ Object
30 31 32 33 |
# File 'lib/fulcrum/client.rb', line 30 def reset @response = nil @connection = nil end |
#roles ⇒ Object
154 155 156 |
# File 'lib/fulcrum/client.rb', line 154 def roles @roles ||= Fulcrum::Role.new(self) end |
#signatures ⇒ Object
126 127 128 |
# File 'lib/fulcrum/client.rb', line 126 def signatures @signatures ||= Fulcrum::Signature.new(self) end |
#videos ⇒ Object
114 115 116 |
# File 'lib/fulcrum/client.rb', line 114 def videos @videos ||= Fulcrum::Video.new(self) end |
#webhooks ⇒ Object
150 151 152 |
# File 'lib/fulcrum/client.rb', line 150 def webhooks @webhooks ||= Fulcrum::Webhook.new(self) end |