stash-client 0.0.7 → 0.0.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 366ade5c848ed2bf054a811a897c6507f37bc9c0
4
- data.tar.gz: 4bc2f3fcb7dfc7bcefd6868a775d1148f7ba6d79
3
+ metadata.gz: fa99f385373b098da9cac5fdf9048414f94ff456
4
+ data.tar.gz: af52892fa50a703ca751a00db2f2b252e24d6821
5
5
  SHA512:
6
- metadata.gz: 0120334e28567dae31f9670b7100d945e70121224ce69b6a1022bd2a1f56ff7cc4eb169e0492ad8c07e53a3dcd98a3f119921509b98f7fa361d5b8ec37454daa
7
- data.tar.gz: b5447d17c342f5202da2b504ee47a1982fabd59916c05f9a504f1f19a36b0484424da4b128de008f5bbb6e3d772358ed1b3d4e80aa4b79a1496fc6928cd9b7cb
6
+ metadata.gz: e2a1b9ece11d5ea77ee5ee6c354d63cd6f1b5ca79a55e96395e9e27a6600c68d2d514bae58f267b0f784808631340a2bba451f81b27b38de29d13ebf5fae3101
7
+ data.tar.gz: ed15abae04ca094ac48cf5d6fc3cdbd55bd15d8cac054cff123849765913a3e3da11e446d3745b5723001cd658bafa8cec84b172abd425db863362bcd8b59b56
data/.gitignore CHANGED
@@ -15,4 +15,5 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
- .ruby-version
18
+ .ruby-version
19
+ .*.sw?
@@ -18,7 +18,7 @@ module Stash
18
18
  elsif opts[:uri] && opts[:uri].kind_of?(Addressable::URI)
19
19
  @url = opts[:uri]
20
20
  else
21
- raise ArgumentError, "must provie :url or :host"
21
+ raise ArgumentError, "must provide :url or :host"
22
22
  end
23
23
 
24
24
  @url.userinfo = opts[:credentials] if opts[:credentials]
@@ -28,11 +28,25 @@ module Stash
28
28
  fetch_all @url.join('projects')
29
29
  end
30
30
 
31
+ def create_project(opts={})
32
+ post @url.join('projects'), opts
33
+ end
34
+
35
+ def update_project(project, opts={})
36
+ relative_project_path = project.fetch('link').fetch('url')
37
+ put @url.join(remove_leading_slash(relative_project_path)), opts
38
+ end
39
+
40
+ def delete_project(project)
41
+ relative_project_path = project.fetch('link').fetch('url')
42
+ delete @url.join(remove_leading_slash(relative_project_path))
43
+ end
44
+
31
45
  def repositories
32
- projects.flat_map do |project|
46
+ projects.map do |project|
33
47
  relative_project_path = project.fetch('link').fetch('url') + '/repos'
34
48
  fetch_all @url.join(remove_leading_slash(relative_project_path))
35
- end
49
+ end.flatten
36
50
  end
37
51
 
38
52
  def project_named(name)
@@ -101,7 +115,27 @@ module Stash
101
115
  end
102
116
 
103
117
  def fetch(uri)
104
- JSON.parse(RestClient.get(uri.to_s, :accept => "application/json"))
118
+ JSON.parse(RestClient.get(uri.to_s, :accept => :json))
119
+ end
120
+
121
+ def post(uri, data)
122
+ JSON.parse(
123
+ RestClient.post(
124
+ uri.to_s, data.to_json, :accept => :json, :content_type => :json
125
+ )
126
+ )
127
+ end
128
+
129
+ def put(uri, data)
130
+ JSON.parse(
131
+ RestClient.put(
132
+ uri.to_s, data.to_json, :accept => :json, :content_type => :json
133
+ )
134
+ )
135
+ end
136
+
137
+ def delete(uri)
138
+ RestClient.delete(uri.to_s, :accept => :json)
105
139
  end
106
140
 
107
141
  def remove_leading_slash(str)
@@ -1,5 +1,5 @@
1
1
  module Stash
2
2
  class Client
3
- VERSION = "0.0.7"
3
+ VERSION = "0.0.8"
4
4
  end
5
5
  end
@@ -1,2 +1,9 @@
1
1
  require 'webmock/rspec'
2
- require 'stash/client'
2
+ require 'stash/client'
3
+
4
+ # Disables the deprecation warning with RSpec 3.0
5
+ RSpec.configure do |config|
6
+ config.expect_with :rspec do |c|
7
+ c.syntax = [:should, :expect]
8
+ end
9
+ end
@@ -18,6 +18,71 @@ module Stash
18
18
  client.projects.should == [{"key" => "value"}]
19
19
  end
20
20
 
21
+ it 'creates projects' do
22
+ stub_request(:post, "foo:bar@git.example.com/rest/api/1.0/projects").
23
+ with(:body => {:key => 'FOO', :name => 'Foobar', :description => 'bar'}).
24
+ to_return(:body => {
25
+ 'id' => 1,
26
+ 'key' => 'FOO',
27
+ 'name' => 'Foobar',
28
+ 'description' => 'bar',
29
+ 'public' => true,
30
+ 'type' => 'NORMAL',
31
+ 'link' => {
32
+ 'url' => 'http://git.example.com/projects/FOO',
33
+ 'rel' => 'self',
34
+ },
35
+ 'links' => {
36
+ 'self' => [
37
+ { 'href' => 'http://git.example.com/projects/FOO' },
38
+ ],
39
+ },
40
+ }.to_json)
41
+
42
+ client.create_project({
43
+ :key => 'FOO', :name => 'Foobar', :description => 'bar'
44
+ }).should == {
45
+ 'id' => 1,
46
+ 'key' => 'FOO',
47
+ 'name' => 'Foobar',
48
+ 'description' => 'bar',
49
+ 'public' => true,
50
+ 'type' => 'NORMAL',
51
+ 'link' => {
52
+ 'url' => 'http://git.example.com/projects/FOO',
53
+ 'rel' => 'self',
54
+ },
55
+ 'links' => {
56
+ 'self' => [
57
+ { 'href' => 'http://git.example.com/projects/FOO' },
58
+ ],
59
+ },
60
+ }
61
+ end
62
+
63
+ it 'updates projects' do
64
+ stub_request(:put, "foo:bar@git.example.com/rest/api/1.0/projects/foo").
65
+ with(:body => {:description => 'new description'}).
66
+ to_return(:body => {
67
+ 'description' => 'new description',
68
+ }.to_json)
69
+
70
+ project = { 'link' => {'url' => '/projects/foo'} }
71
+ client.update_project(project, {
72
+ :description => 'new description'
73
+ }).should == {
74
+ 'description' => 'new description',
75
+ }
76
+ end
77
+
78
+ it 'deletes projects' do
79
+ stub_request(:delete, "foo:bar@git.example.com/rest/api/1.0/projects/foo").
80
+ to_return(:status => 200, :body => "")
81
+
82
+ project = { 'link' => {'url' => '/projects/foo'} }
83
+ client.delete_project(project).should == ""
84
+ end
85
+
21
86
  it 'fetches repositories' do
22
87
  stub_request(:get, "foo:bar@git.example.com/rest/api/1.0/projects").to_return(body: response_with_value('link' => {'url' => '/projects/foo'}))
23
88
  stub_request(:get, "foo:bar@git.example.com/rest/api/1.0/projects/foo/repos").to_return(body: response_with_value('key' => 'value'))
@@ -30,7 +95,7 @@ module Stash
30
95
  client.commits_for({'link' => {'url' => '/repos/foo/browse'}}).should == [{'key' => 'value'}]
31
96
  end
32
97
 
33
- it 'feches changes' do
98
+ it 'fetches changes' do
34
99
  stub_request(:get, 'foo:bar@git.example.com/rest/api/1.0/projects/foo/repos/bar/changes?limit=100&until=deadbeef').to_return(body: response_with_value('key' => 'value'))
35
100
 
36
101
  repo = {'link' => {'url' => '/projects/foo/repos/bar/browse'}}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stash-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jari Bakken
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-04 00:00:00.000000000 Z
11
+ date: 2014-06-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler