Class: Wsapi::Session
- Inherits:
-
Object
- Object
- Wsapi::Session
- Defined in:
- lib/wsapi/session.rb
Instance Attribute Summary collapse
-
#workspace_id ⇒ Object
Returns the value of attribute workspace_id.
Instance Method Summary collapse
- #get_current_user ⇒ Object
- #get_editors(project_id, opts = {}) ⇒ Object
- #get_project(id) ⇒ Object
- #get_projects(opts = {}) ⇒ Object
- #get_subscription(id) ⇒ Object
- #get_team_members(project_id, opts = {}) ⇒ Object
- #get_user(id) ⇒ Object
- #get_user_by_username(username) ⇒ Object
- #get_user_subscription ⇒ Object
-
#initialize(session_id, opts = {}) ⇒ Session
constructor
A new instance of Session.
Constructor Details
#initialize(session_id, opts = {}) ⇒ Session
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/wsapi/session.rb', line 36 def initialize(session_id, opts = {}) @api_version = opts[:version] || "3.0" @session_id = session_id @workspace_id = opts[:workspace_id] @conn = Faraday.new(ssl: { verify: false} ) do |faraday| faraday.request :url_encoded # form-encode POST params faraday.use WsapiAuthentication, @session_id faraday.adapter Faraday.default_adapter # make requests with Net::HTTP end end |
Instance Attribute Details
#workspace_id ⇒ Object
Returns the value of attribute workspace_id.
34 35 36 |
# File 'lib/wsapi/session.rb', line 34 def workspace_id @workspace_id end |
Instance Method Details
#get_current_user ⇒ Object
68 69 70 71 |
# File 'lib/wsapi/session.rb', line 68 def get_current_user response = wsapi_request(wsapi_resource_url("User")) Mapper.get_object(response) end |
#get_editors(project_id, opts = {}) ⇒ Object
89 90 91 92 93 |
# File 'lib/wsapi/session.rb', line 89 def get_editors(project_id, opts = {}) fetch_with_pages(opts) do |page_query| wsapi_request(wsapi_resource_url("Project/#{project_id}/Editors"), opts.merge(page_query)) end end |
#get_project(id) ⇒ Object
63 64 65 66 |
# File 'lib/wsapi/session.rb', line 63 def get_project(id) response = wsapi_request(wsapi_resource_url("Project/#{id}")) Mapper.get_object(response) end |
#get_projects(opts = {}) ⇒ Object
57 58 59 60 61 |
# File 'lib/wsapi/session.rb', line 57 def get_projects(opts = {}) fetch_with_pages(opts) do |page_query| wsapi_request(wsapi_resource_url("Project"), opts.merge(page_query)) end end |
#get_subscription(id) ⇒ Object
52 53 54 55 |
# File 'lib/wsapi/session.rb', line 52 def get_subscription(id) response = wsapi_request(wsapi_resource_url("Subscription/#{id}")) Mapper.get_object(response) end |
#get_team_members(project_id, opts = {}) ⇒ Object
83 84 85 86 87 |
# File 'lib/wsapi/session.rb', line 83 def get_team_members(project_id, opts = {}) fetch_with_pages(opts) do |page_query| wsapi_request(wsapi_resource_url("Project/#{project_id}/TeamMembers"), opts.merge(page_query)) end end |
#get_user(id) ⇒ Object
73 74 75 76 |
# File 'lib/wsapi/session.rb', line 73 def get_user(id) response = wsapi_request(wsapi_resource_url("User/#{id}")) Mapper.get_object(response) end |
#get_user_by_username(username) ⇒ Object
78 79 80 81 |
# File 'lib/wsapi/session.rb', line 78 def get_user_by_username(username) response = wsapi_request(wsapi_resource_url("User"), query: "(UserName = \"#{username}\")", pagesize: 1) (Mapper.get_objects(response) ||[]).first end |
#get_user_subscription ⇒ Object
47 48 49 50 |
# File 'lib/wsapi/session.rb', line 47 def get_user_subscription response = wsapi_request(wsapi_resource_url("Subscription")) Mapper.get_object(response) end |