Class: Workxp::Client
- Inherits:
-
Object
- Object
- Workxp::Client
- Includes:
- Restfulable
- Defined in:
- lib/workxp/client.rb
Constant Summary collapse
- WORKXP_SITE =
"https://workxp.info"
Instance Attribute Summary collapse
-
#access_token ⇒ Object
OAuth2::AccessToken.
-
#sub_domain ⇒ Object
WorkXP product’s subdomain.
Instance Method Summary collapse
- #accounts ⇒ Object
- #activities(opts = {}) ⇒ Object
- #activity(id) ⇒ Object
-
#create_attachment(file_path, file_type) ⇒ Hash
“token”=>“1578a2cd0682359935ae03826fb892701f7c5120”.
- #deletions(opts = {}) ⇒ Object
- #groups ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
-
#oauth_client ⇒ Object
OAuth2::Client instance with WorkxP OAuth.
- #search_activities(opts = {}) ⇒ Object
- #tags ⇒ Object
- #task_categories ⇒ Object
- #user(id) ⇒ Object
- #users(opts = {}) ⇒ Object
- #valid_token ⇒ Object
Methods included from Restfulable
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
32 33 34 35 36 37 38 39 40 |
# File 'lib/workxp/client.rb', line 32 def initialize(opts={}) @app_key = opts.delete :app_key @app_secret = opts.delete :app_secret @workxp_site = opts.delete(:workxp_site) || WORKXP_SITE @user_agent = opts.delete(:user_agent) self.sub_domain = opts.delete :sub_domain self.access_token = OAuth2::AccessToken.new(self.oauth_client, opts[:token], opts) end |
Instance Attribute Details
#access_token ⇒ Object
OAuth2::AccessToken
Store authorized infos
15 16 17 |
# File 'lib/workxp/client.rb', line 15 def access_token @access_token end |
#sub_domain ⇒ Object
WorkXP product’s subdomain. subdomain is your product’s identify. Your can set different subdomain for fetch different product’s data. ruby.workxp.info ‘ruby’ is subdomain
21 22 23 |
# File 'lib/workxp/client.rb', line 21 def sub_domain @sub_domain end |
Instance Method Details
#accounts ⇒ Object
68 69 70 |
# File 'lib/workxp/client.rb', line 68 def accounts valid_token.get("/api/accounts.json", ) end |
#activities(opts = {}) ⇒ Object
72 73 74 |
# File 'lib/workxp/client.rb', line 72 def activities(opts={}) valid_token.get('/api/activities.json', params: opts, headers: domain_hash).parsed end |
#activity(id) ⇒ Object
80 81 82 |
# File 'lib/workxp/client.rb', line 80 def activity(id) valid_token.get("/api/activities/#{id}.json", headers: domain_hash).parsed end |
#create_attachment(file_path, file_type) ⇒ Hash
Returns “token”=>“1578a2cd0682359935ae03826fb892701f7c5120”.
87 88 89 90 |
# File 'lib/workxp/client.rb', line 87 def (file_path, file_type) payload = {file: Faraday::UploadIO.new(file_path, file_type)} valid_token.post("/api/attachments.json", body: payload, headers: {:'Sub-Domain' => sub_domain}).parsed end |
#deletions(opts = {}) ⇒ Object
100 101 102 |
# File 'lib/workxp/client.rb', line 100 def deletions(opts={}) valid_token.get('/api/deletions.json', params: opts, headers: domain_hash).parsed end |
#groups ⇒ Object
96 97 98 |
# File 'lib/workxp/client.rb', line 96 def groups valid_token.get('/api/groups.json', headers: domain_hash).parsed end |
#oauth_client ⇒ Object
OAuth2::Client instance with WorkxP OAuth
43 44 45 46 47 48 49 |
# File 'lib/workxp/client.rb', line 43 def oauth_client @oauth_client ||= OAuth2::Client.new @app_key, @app_secret, site: @workxp_site do |stack| stack.request :multipart stack.request :url_encoded stack.adapter :net_http end end |
#search_activities(opts = {}) ⇒ Object
76 77 78 |
# File 'lib/workxp/client.rb', line 76 def search_activities(opts={}) valid_token.get('/api/activities/search.json', params: opts, headers: domain_hash).parsed end |
#tags ⇒ Object
92 93 94 |
# File 'lib/workxp/client.rb', line 92 def valid_token.get('/api/tags.json', headers: domain_hash).parsed end |
#task_categories ⇒ Object
113 114 115 |
# File 'lib/workxp/client.rb', line 113 def task_categories categories.select {|obj| obj['type'] == 'TaskCategory'} end |
#user(id) ⇒ Object
64 65 66 |
# File 'lib/workxp/client.rb', line 64 def user(id) valid_token.get("/api/users/#{id}.json", headers: domain_hash).parsed end |
#users(opts = {}) ⇒ Object
60 61 62 |
# File 'lib/workxp/client.rb', line 60 def users(opts={}) valid_token.get('/api/users.json', params: opts, headers: domain_hash).parsed end |
#valid_token ⇒ Object
51 52 53 54 55 56 |
# File 'lib/workxp/client.rb', line 51 def valid_token if access_token.expired? self.access_token = access_token.refresh! end self.access_token end |