musashi 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -25,7 +25,6 @@ task :release => :build do
25
25
  system "git push origin master"
26
26
  system "git push origin v#{Musashi::VERSION}"
27
27
  system "gem push build/musashi-#{Musashi::VERSION}.gem"
28
- system "gem push musashi-#{Musashi::VERSION}.gem"
29
28
  end
30
29
 
31
30
  desc 'Run the unit suite'
@@ -0,0 +1,11 @@
1
+ class Musashi::Error < StandardError
2
+ class BadRequest < ::Musashi::Error; end
3
+ class Unauthorized < ::Musashi::Error; end
4
+ class Forbidden < ::Musashi::Error; end
5
+ class NotFound < ::Musashi::Error; end
6
+ class NotAcceptable < ::Musashi::Error; end
7
+ class InternalServer < ::Musashi::Error; end
8
+ class BadGateway < ::Musashi::Error; end
9
+ class ServiceUnavailable < ::Musashi::Error; end
10
+ end
11
+
@@ -1,8 +1,8 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module Musashi::Publisher
3
3
 
4
- def data
5
- @data ||= {}
4
+ def attributes
5
+ @attributes ||= {}
6
6
  end
7
7
 
8
8
  def method_missing(sym,*args,&block)
@@ -10,17 +10,24 @@ module Musashi::Publisher
10
10
  match = /(?<field>.+)=$/.match(sym.to_s)
11
11
  super if match.nil? or match.size != 2
12
12
  field = match[:field]
13
- attrs[field] = data[field] = args.first
13
+ attrs[field] = attributes[field] = args.first
14
+ end
15
+
16
+ def update_attributes(fields)
17
+ self.attrs.merge!(fields)
18
+ self.attributes.merge!(fields)
14
19
  end
15
20
 
16
21
  def post(headers={})
17
- marshall = ::Musashi::Publisher.marshalls[format] || WWWFormUrlencoded
18
- payload, content_type = marshall.marshall(data)
19
- headers = {} if headers.nil?
20
- headers['Content-Type'] = content_type
22
+ payload, headers = post_or_put_prepare(headers)
21
23
  connection.post(connection.path_prefix, payload, headers)
22
24
  end
23
25
 
26
+ def put(headers={})
27
+ payload, headers = post_or_put_prepare(headers)
28
+ connection.put(connection.path_prefix, payload, headers)
29
+ end
30
+
24
31
  def self.marshalls
25
32
  @@marashalls ||= {}
26
33
  end
@@ -30,10 +37,19 @@ module Musashi::Publisher
30
37
  end
31
38
 
32
39
  module WWWFormUrlencoded
33
- def self.marshall(data)
34
- [data.to_query, 'www-form-urlencoded']
40
+ def self.marshall(attributes)
41
+ [attributes.to_query, 'www-form-urlencoded']
35
42
  end
36
43
  end
44
+
45
+ private
46
+ def post_or_put_prepare(headers={})
47
+ marshall = ::Musashi::Publisher.marshalls[format] || WWWFormUrlencoded
48
+ payload, content_type = marshall.marshall(attributes)
49
+ headers = {} if headers.nil?
50
+ headers['Content-Type'] = content_type
51
+ [payload, headers]
52
+ end
37
53
 
38
54
  end
39
55
 
@@ -73,6 +73,14 @@ module Musashi::Retriever
73
73
  Strategist.define(receiver,name)
74
74
  end
75
75
 
76
+ def no_follow
77
+ @no_follow ||= []
78
+ end
79
+
80
+ def follow?(method)
81
+ not (method.nil? || no_follow.include?(method.to_s) || no_follow.include?(method))
82
+ end
83
+
76
84
  end
77
85
 
78
86
  module VisitorStrategist
@@ -94,7 +102,7 @@ module Musashi::Retriever
94
102
  return nil unless self.has_key?(key)
95
103
  value = self.fetch(key.to_s) rescue self.fetch(key) rescue nil
96
104
  return value if value.nil?
97
- define value,key.to_sym
105
+ define value,key.to_sym if follow?(key)
98
106
  value
99
107
  end
100
108
 
@@ -113,7 +121,7 @@ module Musashi::Retriever
113
121
  value = self.fetch(sym.to_s) rescue self.fetch(sym) rescue nil
114
122
  return value if value.nil?
115
123
 
116
- define value, sym
124
+ define value, sym if follow?(sym)
117
125
  value
118
126
  end
119
127
 
@@ -1,4 +1,4 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  module Musashi
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
@@ -7,15 +7,16 @@ describe Musashi::Publisher do
7
7
  @resource = Musashi::Resource.new('http://foo.bar/')
8
8
  FakeWeb.register_uri(:get, @resource.endpoint, :body => '{"foo":"bar","name":"bazz"}')
9
9
  FakeWeb.register_uri(:post, @resource.endpoint, :payload => 'name=bar')
10
+ FakeWeb.register_uri(:post, @resource.endpoint, :payload => {'name'=> 'foo','foo'=> 'bazz'}.to_query)
10
11
  end
11
12
 
12
13
  it 'should known what fields are dirty' do
13
14
  @resource.attrs.size.should == 2
14
- @resource.data.should be_empty
15
+ @resource.attributes.should be_empty
15
16
  @resource.name.should eq('bazz')
16
17
  @resource.name = 'bar'
17
18
  @resource.name.should eq('bar')
18
- @resource.data.size.should == 1
19
+ @resource.attributes.size.should == 1
19
20
  end
20
21
 
21
22
  it 'should post ony fields are dirty' do
@@ -25,5 +26,14 @@ describe Musashi::Publisher do
25
26
  @resource.post
26
27
  end
27
28
 
29
+ it 'should update atributes' do
30
+ @resource.name.should eq('bazz')
31
+ @resource.foo.should eq('bar')
32
+ @resource.update_attributes({'name'=> 'foo', 'foo'=> 'bazz'})
33
+ @resource.attributes['name'].should eq('foo')
34
+ @resource.name.should eq('foo')
35
+ @resource.foo.should eq('bazz')
36
+ end
37
+
28
38
  end
29
39
 
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe Musashi::Retriever::Strategist do
5
+
6
+ describe 'by behavior' do
7
+
8
+ it 'should define a Retriever for Array' do
9
+ Musashi::Retriever::Strategist.define(array = [])
10
+ array.should be_kind_of Musashi::Retriever::Iterator
11
+ end
12
+
13
+ it 'should define a Retriever for url' do
14
+ Musashi::Retriever::Strategist.define(url = 'http://foo.bar/')
15
+ url.should be_kind_of Musashi::Retriever::Content
16
+ end
17
+
18
+ it 'should define a Retriever for hash' do
19
+ Musashi::Retriever::Strategist.define(hash = {})
20
+ hash.should be_kind_of Musashi::Retriever::VisitorStrategist
21
+ end
22
+
23
+ end
24
+
25
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: musashi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-10-10 00:00:00.000000000Z
12
+ date: 2011-10-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: i18n
16
- requirement: &9140160 !ruby/object:Gem::Requirement
16
+ requirement: &13234000 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.6'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *9140160
24
+ version_requirements: *13234000
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: activesupport
27
- requirement: &9139460 !ruby/object:Gem::Requirement
27
+ requirement: &13228720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 3.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *9139460
35
+ version_requirements: *13228720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hashie
38
- requirement: &9138420 !ruby/object:Gem::Requirement
38
+ requirement: &13228160 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 1.1.0
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *9138420
46
+ version_requirements: *13228160
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: faraday
49
- requirement: &9137720 !ruby/object:Gem::Requirement
49
+ requirement: &13227660 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 0.7.4
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *9137720
57
+ version_requirements: *13227660
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: faraday_middleware
60
- requirement: &9123940 !ruby/object:Gem::Requirement
60
+ requirement: &13227120 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 0.7.0
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *9123940
68
+ version_requirements: *13227120
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: multi_json
71
- requirement: &9123480 !ruby/object:Gem::Requirement
71
+ requirement: &13226560 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 1.0.0
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *9123480
79
+ version_requirements: *13226560
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: multi_xml
82
- requirement: &9123020 !ruby/object:Gem::Requirement
82
+ requirement: &13226060 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: 0.4.0
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *9123020
90
+ version_requirements: *13226060
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: rspec
93
- requirement: &9122220 !ruby/object:Gem::Requirement
93
+ requirement: &13225120 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - =
@@ -98,10 +98,10 @@ dependencies:
98
98
  version: 2.6.0
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *9122220
101
+ version_requirements: *13225120
102
102
  - !ruby/object:Gem::Dependency
103
103
  name: sinatra
104
- requirement: &9121760 !ruby/object:Gem::Requirement
104
+ requirement: &13224480 !ruby/object:Gem::Requirement
105
105
  none: false
106
106
  requirements:
107
107
  - - =
@@ -109,10 +109,10 @@ dependencies:
109
109
  version: 1.2.6
110
110
  type: :development
111
111
  prerelease: false
112
- version_requirements: *9121760
112
+ version_requirements: *13224480
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: fakeweb
115
- requirement: &9121260 !ruby/object:Gem::Requirement
115
+ requirement: &13223720 !ruby/object:Gem::Requirement
116
116
  none: false
117
117
  requirements:
118
118
  - - =
@@ -120,7 +120,7 @@ dependencies:
120
120
  version: 1.3.0
121
121
  type: :development
122
122
  prerelease: false
123
- version_requirements: *9121260
123
+ version_requirements: *13223720
124
124
  description: ! 'Musashi is a library for '
125
125
  email: pahagon@gmail.com
126
126
  executables: []
@@ -135,6 +135,7 @@ files:
135
135
  - lib/musashi/resource.rb
136
136
  - lib/musashi/connection.rb
137
137
  - lib/musashi/retriever.rb
138
+ - lib/musashi/error.rb
138
139
  - lib/musashi/version.rb
139
140
  - lib/musashi/publisher.rb
140
141
  - lib/musashi.rb
@@ -142,6 +143,7 @@ files:
142
143
  - lib/faraday/response/raise_http_4xx.rb
143
144
  - spec/connection_spec.rb
144
145
  - spec/spec_helper.rb
146
+ - spec/retriever_visitor_spec.rb
145
147
  - spec/publisher_spec.rb
146
148
  - spec/retriever_base_spec.rb
147
149
  - spec/resource_spec.rb
@@ -176,13 +178,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
178
  version: 1.3.6
177
179
  requirements: []
178
180
  rubyforge_project: musashi
179
- rubygems_version: 1.8.10
181
+ rubygems_version: 1.8.11
180
182
  signing_key:
181
183
  specification_version: 3
182
184
  summary: Musashi is a library for
183
185
  test_files:
184
186
  - spec/connection_spec.rb
185
187
  - spec/spec_helper.rb
188
+ - spec/retriever_visitor_spec.rb
186
189
  - spec/publisher_spec.rb
187
190
  - spec/retriever_base_spec.rb
188
191
  - spec/resource_spec.rb