rally-wsapi 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (7) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/Gemfile.lock +29 -25
  4. data/README.md +5 -0
  5. data/VERSION +1 -1
  6. data/lib/wsapi/session.rb +29 -12
  7. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: df9d5402c89cdb4beac5c876452ceeeb0c5e8212
4
- data.tar.gz: b33483d55a9937b398ba3bb74ebbc23f83a287b6
3
+ metadata.gz: 17422f0570e823b320921612ba38fbf8c63d5ef6
4
+ data.tar.gz: 7828a43b5cfbc90dc01a35e139f9b17119468026
5
5
  SHA512:
6
- metadata.gz: 938bb18802fcf075893e6dce86bd4e0024820b141f80cd0e344060d89b5954270d0fe7c89e4c3c591bcccc3232364d8f37d5c6b9db8ba17a96fe4b70d57ab3cb
7
- data.tar.gz: ef8dc6cb65857ff56d48a418481d37dba8f730065b3ebaf202f8edc621f7f57f302d33b76c1e98608e77e134eb9123830de0d8ca7117f6a6012da1646665bbd7
6
+ metadata.gz: 1f402a6482ca688e0edb1bb01ef7953489e85e6b15a724223104a6aa748a49eceb61df492d80df6c54627894134c2979b326aa81d9bf0606339245cd97954944
7
+ data.tar.gz: 92f3c7564ca5b12c9bba798bcf5901b4365292b128d67dd990c82afd581fdec09482d6cc9da11fe157f28e14d799eecad044b67b0655b545c28961cdadaa1ba8
data/Gemfile CHANGED
@@ -1,6 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
1
3
  gem 'rake'
2
4
  gem 'multi_json'
3
5
  gem 'faraday'
6
+ gem 'faraday_middleware'
4
7
  gem 'excon'
5
8
 
6
9
  group :release do
data/Gemfile.lock CHANGED
@@ -1,4 +1,5 @@
1
1
  GEM
2
+ remote: https://rubygems.org/
2
3
  specs:
3
4
  addressable (2.3.6)
4
5
  builder (3.2.2)
@@ -7,19 +8,21 @@ GEM
7
8
  descendants_tracker (0.0.4)
8
9
  thread_safe (~> 0.3, >= 0.3.1)
9
10
  diff-lcs (1.2.5)
10
- excon (0.40.0)
11
+ excon (0.42.1)
11
12
  faraday (0.9.0)
12
13
  multipart-post (>= 1.2, < 3)
14
+ faraday_middleware (0.9.1)
15
+ faraday (>= 0.7.4, < 0.10)
13
16
  git (1.2.8)
14
- github_api (0.11.3)
17
+ github_api (0.12.2)
15
18
  addressable (~> 2.3)
16
- descendants_tracker (~> 0.0.1)
19
+ descendants_tracker (~> 0.0.4)
17
20
  faraday (~> 0.8, < 0.10)
18
- hashie (>= 1.2)
21
+ hashie (>= 3.3)
19
22
  multi_json (>= 1.7.5, < 2.0)
20
- nokogiri (~> 1.6.0)
23
+ nokogiri (~> 1.6.3)
21
24
  oauth2
22
- hashie (3.2.0)
25
+ hashie (3.3.2)
23
26
  highline (1.6.21)
24
27
  jeweler (2.0.1)
25
28
  builder
@@ -31,13 +34,13 @@ GEM
31
34
  rake
32
35
  rdoc
33
36
  json (1.8.1)
34
- jwt (1.0.0)
35
- mini_portile (0.6.0)
37
+ jwt (1.2.0)
38
+ mini_portile (0.6.1)
36
39
  multi_json (1.10.1)
37
40
  multi_xml (0.5.5)
38
41
  multipart-post (2.0.0)
39
- nokogiri (1.6.3.1)
40
- mini_portile (= 0.6.0)
42
+ nokogiri (1.6.5)
43
+ mini_portile (~> 0.6.0)
41
44
  oauth2 (1.0.0)
42
45
  faraday (>= 0.8, < 0.10)
43
46
  jwt (~> 1.0)
@@ -45,24 +48,24 @@ GEM
45
48
  multi_xml (~> 0.5)
46
49
  rack (~> 1.2)
47
50
  rack (1.5.2)
48
- rake (10.3.2)
49
- rdoc (4.1.1)
51
+ rake (10.4.2)
52
+ rdoc (4.2.0)
50
53
  json (~> 1.4)
51
- rspec (3.0.0)
52
- rspec-core (~> 3.0.0)
53
- rspec-expectations (~> 3.0.0)
54
- rspec-mocks (~> 3.0.0)
55
- rspec-core (3.0.4)
56
- rspec-support (~> 3.0.0)
57
- rspec-expectations (3.0.4)
54
+ rspec (3.1.0)
55
+ rspec-core (~> 3.1.0)
56
+ rspec-expectations (~> 3.1.0)
57
+ rspec-mocks (~> 3.1.0)
58
+ rspec-core (3.1.7)
59
+ rspec-support (~> 3.1.0)
60
+ rspec-expectations (3.1.2)
58
61
  diff-lcs (>= 1.2.0, < 2.0)
59
- rspec-support (~> 3.0.0)
60
- rspec-mocks (3.0.4)
61
- rspec-support (~> 3.0.0)
62
- rspec-support (3.0.4)
63
- safe_yaml (1.0.3)
62
+ rspec-support (~> 3.1.0)
63
+ rspec-mocks (3.1.3)
64
+ rspec-support (~> 3.1.0)
65
+ rspec-support (3.1.2)
66
+ safe_yaml (1.0.4)
64
67
  thread_safe (0.3.4)
65
- webmock (1.18.0)
68
+ webmock (1.20.4)
66
69
  addressable (>= 2.3.6)
67
70
  crack (>= 0.3.2)
68
71
 
@@ -72,6 +75,7 @@ PLATFORMS
72
75
  DEPENDENCIES
73
76
  excon
74
77
  faraday
78
+ faraday_middleware
75
79
  jeweler
76
80
  multi_json
77
81
  rake
data/README.md CHANGED
@@ -70,6 +70,11 @@ get_team_members(project_id, opts = {})
70
70
  get_editors(project_id, opts = {})
71
71
  ```
72
72
 
73
+ ### Update any artifact with parameters hash
74
+ ```
75
+ update_artifact(artifact_type, artifact_id, parameters)
76
+ ```
77
+
73
78
  ## Result objects
74
79
 
75
80
  There's a couple of convenience classes for the following object types:
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/lib/wsapi/session.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require 'multi_json'
2
2
  require 'faraday'
3
+ require 'faraday_middleware'
3
4
  require 'excon'
4
5
 
5
6
  require_relative './mapper'
@@ -39,60 +40,65 @@ module Wsapi
39
40
  @session_id = session_id
40
41
  @workspace_id = opts[:workspace_id]
41
42
  @conn = Faraday.new(ssl: {version: :TLSv1}) do |faraday|
42
- faraday.request :url_encoded # form-encode POST params
43
+ faraday.request :json
43
44
  faraday.use WsapiAuthentication, @session_id
44
45
  faraday.adapter :excon
45
46
  end
46
47
  end
47
48
 
48
49
  def get_user_subscription
49
- response = wsapi_request(wsapi_resource_url("Subscription"))
50
+ response = wsapi_get(wsapi_resource_url("Subscription"))
50
51
  Mapper.get_object(response)
51
52
  end
52
53
 
53
54
  def get_subscription(id)
54
- response = wsapi_request(wsapi_resource_url("Subscription/#{id}"))
55
+ response = wsapi_get(wsapi_resource_url("Subscription/#{id}"))
55
56
  Mapper.get_object(response)
56
57
  end
57
58
 
58
59
  def get_projects(opts = {})
59
60
  fetch_with_pages(opts) do |page_query|
60
- wsapi_request(wsapi_resource_url("Project"), opts.merge(page_query))
61
+ wsapi_get(wsapi_resource_url("Project"), opts.merge(page_query))
61
62
  end
62
63
  end
63
64
 
64
65
  def get_project(id)
65
- response = wsapi_request(wsapi_resource_url("Project/#{id}"))
66
+ response = wsapi_get(wsapi_resource_url("Project/#{id}"))
66
67
  Mapper.get_object(response)
67
68
  end
68
69
 
69
70
  def get_current_user
70
- response = wsapi_request(wsapi_resource_url("User"))
71
+ response = wsapi_get(wsapi_resource_url("User"))
71
72
  Mapper.get_object(response)
72
73
  end
73
74
 
74
75
  def get_user(id)
75
- response = wsapi_request(wsapi_resource_url("User/#{id}"))
76
+ response = wsapi_get(wsapi_resource_url("User/#{id}"))
76
77
  Mapper.get_object(response)
77
78
  end
78
79
 
79
80
  def get_user_by_username(username)
80
- response = wsapi_request(wsapi_resource_url("User"), query: "(UserName = \"#{username}\")", pagesize: 1)
81
+ response = wsapi_get(wsapi_resource_url("User"), query: "(UserName = \"#{username}\")", pagesize: 1)
81
82
  (Mapper.get_objects(response) ||[]).first
82
83
  end
83
84
 
84
85
  def get_team_members(project_id, opts = {})
85
86
  fetch_with_pages(opts) do |page_query|
86
- wsapi_request(wsapi_resource_url("Project/#{project_id}/TeamMembers"), opts.merge(page_query))
87
+ wsapi_get(wsapi_resource_url("Project/#{project_id}/TeamMembers"), opts.merge(page_query))
87
88
  end
88
89
  end
89
90
 
90
91
  def get_editors(project_id, opts = {})
91
92
  fetch_with_pages(opts) do |page_query|
92
- wsapi_request(wsapi_resource_url("Project/#{project_id}/Editors"), opts.merge(page_query))
93
+ wsapi_get(wsapi_resource_url("Project/#{project_id}/Editors"), opts.merge(page_query))
93
94
  end
94
95
  end
95
96
 
97
+ def update_artifact(type, id, update_hash)
98
+ response = wsapi_post(wsapi_resource_url("#{type}/#{id}"), "#{type}" => update_hash)
99
+ Mapper.get_object(response)
100
+ end
101
+
96
102
  private
97
103
 
98
104
  def workspace_url
@@ -103,7 +109,14 @@ module Wsapi
103
109
  File.join(WSAPI_URL, "v#{@api_version}", resource)
104
110
  end
105
111
 
106
- def wsapi_request(url, opts = {})
112
+ def wsapi_post(url, opts = {})
113
+ response = @conn.post url, opts
114
+ check_response_for_errors!(response)
115
+
116
+ response
117
+ end
118
+
119
+ def wsapi_get(url, opts = {})
107
120
  response = @conn.get do |req|
108
121
  req.url url
109
122
  req.params['workspace'] = workspace_url if @workspace_id
@@ -112,12 +125,16 @@ module Wsapi
112
125
  req.params['pagesize'] = opts[:pagesize] || 200
113
126
  req.params['fetch'] = opts[:fetch] || true # by default, fetch full objects
114
127
  end
128
+ check_response_for_errors!(response)
129
+ response
130
+ end
131
+
132
+ def check_response_for_errors!(response)
115
133
  raise AuthorizationError.new("Unauthorized", response) if response.status == 401 || response.status == 403
116
134
  raise ApiError.new("Internal server error", response) if response.status == 500
117
135
  raise ApiError.new("Service unavailable", response) if response.status == 503
118
136
  raise ObjectNotFoundError.new("Object not found") if object_not_found?(response)
119
137
  raise IpAddressLimited.new("IP Address limited", response) if ip_address_limited?(response)
120
- response
121
138
  end
122
139
 
123
140
  def ip_address_limited?(response)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rally-wsapi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antti Pitkänen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-13 00:00:00.000000000 Z
11
+ date: 2014-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday_middleware
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: excon
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -107,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
107
121
  version: '0'
108
122
  requirements: []
109
123
  rubyforge_project:
110
- rubygems_version: 2.2.1
124
+ rubygems_version: 2.2.2
111
125
  signing_key:
112
126
  specification_version: 4
113
127
  summary: Simple client for Rally WSAPI