Class: Wsapi::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/wsapi/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(session_id, opts = {}) ⇒ Session

Returns a new instance of Session.



40
41
42
43
44
45
# File 'lib/wsapi/session.rb', line 40

def initialize(session_id, opts = {})
  @api_version = opts[:version] || "3.0"
  @workspace_id = opts[:workspace_id]
  @timeout = opts[:timeout]
  @conn = connection(session_id)
end

Instance Attribute Details

#workspace_idObject

Returns the value of attribute workspace_id.



38
39
40
# File 'lib/wsapi/session.rb', line 38

def workspace_id
  @workspace_id
end

Instance Method Details

#build_object_url(type, id) ⇒ Object



47
48
49
# File 'lib/wsapi/session.rb', line 47

def build_object_url(type, id)
  wsapi_resource_url("#{type}/#{id}").sub('userstory', 'hierarchicalrequirement')
end

#create(type, fields) ⇒ Object



51
52
53
54
# File 'lib/wsapi/session.rb', line 51

def create(type, fields)
  response = wsapi_request(:put, wsapi_resource_url("#{type}/create"), type => fields)
  Mapper.get_object(response)
end

#get_current_userObject



56
57
58
59
# File 'lib/wsapi/session.rb', line 56

def get_current_user
  response = wsapi_get(wsapi_resource_url("User"))
  Mapper.get_object(response)
end

#get_editors(project_id, opts = {}) ⇒ Object



61
62
63
64
65
# File 'lib/wsapi/session.rb', line 61

def get_editors(project_id, opts = {})
  fetch_with_pages(opts) do |page_query|
    wsapi_get(wsapi_resource_url("Project/#{project_id}/Editors"), opts.merge(page_query))
  end
end

#get_project(id) ⇒ Object



67
68
69
70
# File 'lib/wsapi/session.rb', line 67

def get_project(id)
  response = wsapi_get(wsapi_resource_url("Project/#{id}"))
  Mapper.get_object(response)
end

#get_projects(opts = {}) ⇒ Object



72
73
74
75
76
# File 'lib/wsapi/session.rb', line 72

def get_projects(opts = {})
  fetch_with_pages(opts) do |page_query|
    wsapi_get(wsapi_resource_url("Project"), opts.merge(page_query))
  end
end

#get_subscription(id) ⇒ Object



78
79
80
81
# File 'lib/wsapi/session.rb', line 78

def get_subscription(id)
  response = wsapi_get(wsapi_resource_url("Subscription/#{id}"))
  Mapper.get_object(response)
end

#get_subscription_by_subscription_id(subscription_id) ⇒ Object



83
84
85
86
# File 'lib/wsapi/session.rb', line 83

def get_subscription_by_subscription_id(subscription_id)
  response = wsapi_get(wsapi_resource_url("Subscription"), query: "(SubscriptionId = #{subscription_id})", pagesize: 1)
  (Mapper.get_objects(response) ||[]).first
end

#get_team_members(project_id, opts = {}) ⇒ Object



88
89
90
91
92
# File 'lib/wsapi/session.rb', line 88

def get_team_members(project_id, opts = {})
  fetch_with_pages(opts) do |page_query|
    wsapi_get(wsapi_resource_url("Project/#{project_id}/TeamMembers"), opts.merge(page_query))
  end
end

#get_user(id) ⇒ Object



94
95
96
97
# File 'lib/wsapi/session.rb', line 94

def get_user(id)
  response = wsapi_get(wsapi_resource_url("User/#{id}"))
  Mapper.get_object(response)
end

#get_user_by_username(username) ⇒ Object



99
100
101
102
# File 'lib/wsapi/session.rb', line 99

def get_user_by_username(username)
  response = wsapi_get(wsapi_resource_url("User"), query: "(UserName = \"#{username}\")", pagesize: 1)
  (Mapper.get_objects(response) ||[]).first
end

#get_user_subscriptionObject



104
105
106
107
# File 'lib/wsapi/session.rb', line 104

def get_user_subscription
  response = wsapi_get(wsapi_resource_url("Subscription"))
  Mapper.get_object(response)
end

#get_users(query = nil) ⇒ Object



109
110
111
112
113
114
115
116
117
118
# File 'lib/wsapi/session.rb', line 109

def get_users(query = nil)
  fetch_with_pages do |page_query|
    if query
      query_hash = { query: "(#{query})" }
      wsapi_get(wsapi_resource_url("User"), query_hash.merge(page_query))
    else
      wsapi_get(wsapi_resource_url("Users"), page_query)
    end
  end
end

#setup_refresh_token(client_id, client_secret, refresh_token, &block) ⇒ Object



120
121
122
123
124
125
126
127
# File 'lib/wsapi/session.rb', line 120

def setup_refresh_token(client_id, client_secret, refresh_token, &block)
  @oauth2 = {
    client_id: client_id,
    client_secret: client_secret,
    refresh_token: refresh_token,
    refresh_token_updated: block
  }
end

#update(type, id, update_hash) ⇒ Object



129
130
131
132
# File 'lib/wsapi/session.rb', line 129

def update(type, id, update_hash)
  response = wsapi_request(:post, wsapi_resource_url("#{type}/#{id}"), type => update_hash)
  Mapper.get_object(response)
end

#update_artifact(type, id, update_hash) ⇒ Object

This method is deprecated and will be removed in a future release.



135
136
137
138
# File 'lib/wsapi/session.rb', line 135

def update_artifact(type, id, update_hash)
  puts "WsapiAuthentication::Session#update_artifact has been deprecated. Please use #update instead."
  update(type, id, update_hash)
end