Class: GoodData::Client
- Inherits:
-
Rest::Resource
- Object
- Rest::Object
- Rest::Resource
- GoodData::Client
- Includes:
- Mixin::Links, Mixin::UriGetter
- Defined in:
- lib/gooddata/models/client.rb
Constant Summary collapse
- CLIENT_TEMPLATE =
{ client: { id: nil, segment: nil, project: nil } }
Instance Attribute Summary collapse
-
#domain ⇒ Object
Returns the value of attribute domain.
Attributes inherited from Rest::Object
Class Method Summary collapse
- .[](id, opts = {}) ⇒ Object
-
.create(data, options) ⇒ GoodData::Client
Creates new client from parameters passed.
- .update_setting(name, value, opts = {}) ⇒ Object (also: add_setting)
Instance Method Summary collapse
-
#client_id ⇒ String
Segment id getter for the Segment.
- #client_id=(a_name) ⇒ Object
-
#delete ⇒ GoodData::Client
Deletes a client instance on the API.
-
#initialize(data) ⇒ Client
constructor
A new instance of Client.
-
#project ⇒ GoodData::Project
Project this client has set.
-
#project=(a_project) ⇒ GoodData::Cliet
Setter for the project this client has set.
-
#project? ⇒ Boolean
Returns boolean if client has a project provisioned.
-
#project_uri ⇒ String
Project URI this client has set.
-
#reload! ⇒ GoodData::Client
Reloads the client from the URI.
-
#save ⇒ GoodData::Client
Creates or updates a client instance on the API.
-
#segment ⇒ GoodData::Segment
Segment this client is connected to.
-
#segment=(a_segment) ⇒ GoodData::Client
Segment id setter which this client is connected to.
-
#segment_uri ⇒ String
Segment URI this client is connected to.
- #settings ⇒ Object
Methods included from Mixin::UriGetter
Methods included from Mixin::Links
Methods included from Mixin::ObjId
Methods inherited from Rest::Object
client, default_client, #saved?
Methods included from Mixin::DataPropertyReader
Methods included from Mixin::DataPropertyWriter
Methods included from Mixin::MetaPropertyReader
Methods included from Mixin::MetaPropertyWriter
Methods included from Mixin::MetaGetter
Methods included from Mixin::DataGetter
Methods included from Mixin::RootKeyGetter
Methods included from Mixin::ContentGetter
Constructor Details
#initialize(data) ⇒ Client
Returns a new instance of Client.
103 104 105 106 107 |
# File 'lib/gooddata/models/client.rb', line 103 def initialize(data) super(data) @domain = data.delete('domain') @json = data end |
Instance Attribute Details
#domain ⇒ Object
Returns the value of attribute domain.
18 19 20 |
# File 'lib/gooddata/models/client.rb', line 18 def domain @domain end |
Class Method Details
.[](id, opts = {}) ⇒ Object
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 61 62 |
# File 'lib/gooddata/models/client.rb', line 32 def [](id, opts = {}) domain = opts[:domain] segment = opts[:segment] fail ArgumentError, 'No :domain specified' if domain.nil? fail ArgumentError, 'No :segment specified' if domain.nil? client = domain.client fail ArgumentError, 'No client specified' if client.nil? if id == :all tenants_uri = domain.segments_uri + "/clients?segment=#{CGI.escape(segment.segment_id)}" Enumerator.new do |y| loop do res = client.get tenants_uri res['clients']['paging']['next'] res['clients']['items'].each do |i| p = i['client']['project'] tenant = client.create(GoodData::Client, i.merge('domain' => domain)) tenant.project = p y << tenant end url = res['clients']['paging']['next'] break unless url end end else id = id.respond_to?(:client_id) ? id.client_id : id data = client.get(domain.segments_uri + "/clients/#{CGI.escape(id)}") client.create(GoodData::Client, data.merge('domain' => domain)) end end |
.create(data, options) ⇒ GoodData::Client
Creates new client from parameters passed.
Should not be called directly. Use GoodData::Segment#create_client.
75 76 77 78 79 80 81 82 83 84 |
# File 'lib/gooddata/models/client.rb', line 75 def create(data, ) segment = [:segment] domain = segment.domain tenant = client.create(GoodData::Client, GoodData::Helpers.stringify_keys(CLIENT_TEMPLATE.merge(domain: domain)), domain: domain) tenant.tap do |s| s.project = data[:project] s.client_id = data[:id] s.segment = segment.uri end end |
.update_setting(name, value, opts = {}) ⇒ Object Also known as: add_setting
86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/gooddata/models/client.rb', line 86 def update_setting(name, value, opts = {}) return nil unless value domain = opts[:domain] client_id = opts[:client_id] uri = "#{domain.segments_uri}/clients/#{client_id}/settings/#{name}" body = { setting: { name: "#{name}", value: "#{value}" } } domain.client.put(uri, body) nil end |
Instance Method Details
#client_id ⇒ String
Segment id getter for the Segment. Called segment_id since id is a reserved word in ruby world
112 113 114 |
# File 'lib/gooddata/models/client.rb', line 112 def client_id data['id'] end |
#client_id=(a_name) ⇒ Object
116 117 118 119 |
# File 'lib/gooddata/models/client.rb', line 116 def client_id=(a_name) data['id'] = a_name self end |
#delete ⇒ GoodData::Client
Deletes a client instance on the API.
200 201 202 203 |
# File 'lib/gooddata/models/client.rb', line 200 def delete project.delete if project && !project.deleted? client.delete(uri) if uri end |
#project ⇒ GoodData::Project
Project this client has set
140 141 142 |
# File 'lib/gooddata/models/client.rb', line 140 def project client.projects(project_uri) if project? end |
#project=(a_project) ⇒ GoodData::Cliet
Setter for the project this client has set
125 126 127 128 |
# File 'lib/gooddata/models/client.rb', line 125 def project=(a_project) data['project'] = a_project.respond_to?(:uri) ? a_project.uri : a_project self end |
#project? ⇒ Boolean
Returns boolean if client has a project provisioned
147 148 149 |
# File 'lib/gooddata/models/client.rb', line 147 def project? project_uri != nil end |
#project_uri ⇒ String
Project URI this client has set
133 134 135 |
# File 'lib/gooddata/models/client.rb', line 133 def project_uri data['project'] end |
#reload! ⇒ GoodData::Client
Reloads the client from the URI
154 155 156 157 158 |
# File 'lib/gooddata/models/client.rb', line 154 def reload! res = client.get(uri) @json = res self end |
#save ⇒ GoodData::Client
Creates or updates a client instance on the API.
187 188 189 190 191 192 193 194 195 |
# File 'lib/gooddata/models/client.rb', line 187 def save if uri client.put(uri, json) else res = client.post(domain.segments_uri + '/clients', json) @json = res end self end |
#segment ⇒ GoodData::Segment
Segment this client is connected to.
172 173 174 175 |
# File 'lib/gooddata/models/client.rb', line 172 def segment segment_res = client.get(data['segment']) client.create(GoodData::Segment, segment_res) end |
#segment=(a_segment) ⇒ GoodData::Client
Segment id setter which this client is connected to.
164 165 166 167 |
# File 'lib/gooddata/models/client.rb', line 164 def segment=(a_segment) data['segment'] = a_segment.respond_to?(:uri) ? a_segment.uri : a_segment self end |
#segment_uri ⇒ String
Segment URI this client is connected to.
180 181 182 |
# File 'lib/gooddata/models/client.rb', line 180 def segment_uri data['segment'] end |
#settings ⇒ Object
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/gooddata/models/client.rb', line 205 def settings uri = "#{domain.segments_uri}/clients/#{client_id}/settings" res = client.get(uri) settings = GoodData::Helpers.get_path(res, %w(settingsList items)) settings.map do |setting| setting = setting['setting'] { name: setting['name'], value: setting['value'] } end end |