mikyung 0.7.0 → 0.7.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -113,7 +113,7 @@ h2. Objective examples
113
113
  You can create your own objective builders, with the required conditions that your goal achiever requires.
114
114
  Mikyung provides one objective builder called *RelationDrivenObjective* to describe how to use it. The following example shows how to achieve a buying objective:
115
115
 
116
- [pre]
116
+ <pre>
117
117
  class Buy < RelationDrivenObjective
118
118
 
119
119
  executes FinishesOrder, :when => has_relation(:payment)
@@ -125,12 +125,12 @@ class Buy < RelationDrivenObjective
125
125
  end
126
126
 
127
127
  end
128
- [/pre]
128
+ </pre>
129
129
 
130
130
 
131
131
  A less declarative approach is to implement both the completed? and *next_step* methods:
132
132
 
133
- [pre]
133
+ <pre>
134
134
  class Buy
135
135
 
136
136
  def completed?(resource)
@@ -146,4 +146,4 @@ class Buy
146
146
  end
147
147
 
148
148
  end
149
- [/pre]
149
+ </pre>
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ require 'spec/rake/spectask'
6
6
  require 'rake/rdoctask'
7
7
 
8
8
  GEM = "mikyung"
9
- GEM_VERSION = "0.7.0"
9
+ GEM_VERSION = "0.7.3"
10
10
  SUMMARY = "Mikyung is a restful client built on top of Restfulie that allows real rest clients to be built."
11
11
  AUTHOR = "Guilherme Silveira"
12
12
  EMAIL = "guilherme.silveira@caelum.com.br"
@@ -19,7 +19,7 @@ spec = Gem::Specification.new do |s|
19
19
  s.summary = SUMMARY
20
20
  s.require_paths = ['lib']
21
21
  s.files = FileList['lib/**/*.rb', '[A-Z]*'].to_a
22
- s.add_dependency("restfulie", [">= 0.7.0"])
22
+ s.add_dependency("restfulie", [">= 0.7.2"])
23
23
 
24
24
  s.author = AUTHOR
25
25
  s.email = EMAIL
@@ -26,7 +26,7 @@ class RelationDrivenObjective
26
26
  step = internals.find do |k|
27
27
  k.first.matches?(resource)
28
28
  end
29
- step ? step.last : nil
29
+ step ? step.last : nil
30
30
  end
31
31
 
32
32
  private
@@ -38,28 +38,31 @@ class RelationDrivenObjective
38
38
  end
39
39
 
40
40
 
41
-
42
41
  # iterates following a series of steps provided a goal and a starting uri.
43
42
  #
44
43
  # Mikyung.new(objective).run(uri)
45
44
  class Mikyung
46
45
 
46
+ attr_reader :start, :goal
47
+
47
48
  # initializes with a goal in mind
48
- def initialize(goal)
49
- @goal = goal
49
+ def initialize(*args)
50
+ @goal = args[0]
51
+ @start = args[1] if args.size==2
50
52
  end
51
53
 
52
54
  # keeps changing from a steady state to another until its goal has been achieved
53
- def run(uri)
55
+ def run(*args)
54
56
 
55
- current = Restfulie.at(uri).get!
57
+ @start = current = @start || Restfulie.at(args[0]).get
56
58
  Restfulie::Common::Logger.logger.debug current.response.body
57
59
 
58
60
  while(!@goal.completed?(current))
59
61
  step = @goal.next_step(current)
60
62
  raise "No step was found for #{current} with links #{current.links}" unless step
61
63
  Restfulie::Common::Logger.logger.debug "Mikyung > next step will be #{step}"
62
- current = try_to_execute(step.new, current, 3)
64
+ step = step.new if step.kind_of? Class
65
+ current = try_to_execute(step, current, 3)
63
66
  end
64
67
 
65
68
  end
@@ -69,7 +72,10 @@ class Mikyung
69
72
  def try_to_execute(step, current, max_attempts)
70
73
  raise "Unable to proceed when trying to #{step}" if max_attempts == 0
71
74
 
72
- resource = step.execute(current)
75
+ resource = step.execute(current, self)
76
+ if resource==nil
77
+ raise "Step returned 'give up'"
78
+ end
73
79
  if resource.response.code != 200
74
80
  try_to_execute(step, max_attempts - 1)
75
81
  else
@@ -4,6 +4,10 @@ class OpenSearchEngine
4
4
  @description = Restfulie.accepts("application/opensearchdescription+xml").at(uri).get!
5
5
  end
6
6
 
7
+ def get!(content)
8
+ post!(content)
9
+ end
10
+
7
11
  def post!(terms)
8
12
  urls = @description["OpenSearchDescription"]["Url"]
9
13
  uri = urls["template"].gsub("{searchTerms}", terms).gsub("{startPage?}","1")
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mikyung
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 7
8
+ - 3
9
+ version: 0.7.3
5
10
  platform: ruby
6
11
  authors:
7
12
  - Guilherme Silveira
@@ -9,19 +14,23 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2010-04-08 00:00:00 -03:00
17
+ date: 2010-05-11 00:00:00 -03:00
13
18
  default_executable:
14
19
  dependencies:
15
20
  - !ruby/object:Gem::Dependency
16
21
  name: restfulie
17
- type: :runtime
18
- version_requirement:
19
- version_requirements: !ruby/object:Gem::Requirement
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
20
24
  requirements:
21
25
  - - ">="
22
26
  - !ruby/object:Gem::Version
23
- version: 0.7.0
24
- version:
27
+ segments:
28
+ - 0
29
+ - 7
30
+ - 2
31
+ version: 0.7.2
32
+ type: :runtime
33
+ version_requirements: *id001
25
34
  description:
26
35
  email: guilherme.silveira@caelum.com.br
27
36
  executables: []
@@ -49,18 +58,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
49
58
  requirements:
50
59
  - - ">="
51
60
  - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
52
63
  version: "0"
53
- version:
54
64
  required_rubygems_version: !ruby/object:Gem::Requirement
55
65
  requirements:
56
66
  - - ">="
57
67
  - !ruby/object:Gem::Version
68
+ segments:
69
+ - 0
58
70
  version: "0"
59
- version:
60
71
  requirements: []
61
72
 
62
73
  rubyforge_project:
63
- rubygems_version: 1.3.5
74
+ rubygems_version: 1.3.6
64
75
  signing_key:
65
76
  specification_version: 3
66
77
  summary: Mikyung is a restful client built on top of Restfulie that allows real rest clients to be built.