ixtlan 0.4.0.pre2 → 0.4.0.pre3

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 (37) hide show
  1. data/generators/gwt_ixtlan_datamapper_rspec_scaffold/gwt_ixtlan_datamapper_rspec_scaffold_generator.rb +1 -1
  2. data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Fields.java +13 -0
  3. data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Model.java +11 -14
  4. data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/ModelFactory.java +2 -7
  5. data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/Screen.java +14 -7
  6. data/generators/gwt_ixtlan_datamapper_rspec_scaffold/templates/TestGwt.java +12 -10
  7. data/generators/ixtlan_datamapper_model/templates/migration.rb +22 -0
  8. data/generators/ixtlan_datamapper_model/templates/model.rb +2 -2
  9. data/generators/ixtlan_datamapper_rspec_model/ixtlan_datamapper_rspec_model_generator.rb +2 -0
  10. data/generators/ixtlan_datamapper_rspec_model/templates/model_spec.rb +8 -5
  11. data/generators/ixtlan_datamapper_rspec_scaffold/ixtlan_datamapper_rspec_scaffold_generator.rb +2 -0
  12. data/generators/ixtlan_datamapper_rspec_scaffold/templates/controller_spec.rb +13 -7
  13. data/lib/dm-serializer/to_xml.rb +2 -2
  14. data/lib/ixtlan/controllers/authentications_controller.rb +1 -1
  15. data/lib/ixtlan/controllers/locales_controller.rb +1 -0
  16. data/lib/ixtlan/controllers/users_controller.rb +5 -3
  17. data/lib/ixtlan/models/authentication.rb +1 -3
  18. data/lib/ixtlan/models/i18n_text.rb +4 -4
  19. data/lib/ixtlan/models/user.rb +2 -0
  20. data/lib/ixtlan/models/word.rb +3 -1
  21. data/lib/ixtlan/modified_by.rb +1 -1
  22. data/lib/ixtlan/optimistic_persistence.rb +2 -5
  23. data/lib/ixtlan/rails/migrations.rb +30 -25
  24. data/lib/ixtlan/rails/unrestful_authentication.rb +1 -1
  25. data/lib/ixtlan/session.rb +2 -2
  26. data/lib/ixtlan/simple_client.rb +126 -0
  27. data/lib/ixtlan/user_logger.rb +0 -1
  28. data/lib/ixtlan/version.rb +1 -1
  29. data/lib/models.rb +1 -0
  30. metadata +267 -219
  31. data/History.txt +0 -49
  32. data/MIT-LICENSE +0 -20
  33. data/Manifest.txt +0 -103
  34. data/README.txt +0 -86
  35. data/Rakefile +0 -55
  36. data/ixtlan_rails_templates.rb +0 -537
  37. data/whitespace.rb +0 -31
@@ -8,12 +8,12 @@ module Ixtlan
8
8
  @user = d.delete(:user)
9
9
  @flash = d.delete(:flash)
10
10
  @expires_at = d.delete(:expires_at)
11
- attribute_set(:data, ::Base64.encode64(Marshal.dump(d)))
11
+ attribute_set(:raw_data, ::Base64.encode64(Marshal.dump(d)))
12
12
  end
13
13
 
14
14
  def data
15
15
  # user string for flash entry to allow the rails falsh to work properly !
16
- Marshal.load(::Base64.decode64(attribute_get(:data))).merge({:user => @user, "flash" => @flash, :expires_at => @expires_at})
16
+ Marshal.load(::Base64.decode64(attribute_get(:raw_data))).merge({:user => @user, "flash" => @flash, :expires_at => @expires_at})
17
17
  end
18
18
  end
19
19
  end
@@ -0,0 +1,126 @@
1
+ require 'net/http'
2
+ module Ixtlan
3
+ class NoAuthenticationError < StandardError; end
4
+
5
+ # restful XML client using HTTP (no HTTPS support !!)
6
+ class SimpleClient
7
+
8
+ def initialize(options)
9
+ @host = options[:host]
10
+ @port = (options[:port] || 80).to_i # defaults to 80
11
+ @username = options[:username]
12
+ @password = options[:password]
13
+ end
14
+
15
+ # restful get for the given path (like '/users.xml' or '/users/1.xml').
16
+ # which retrieves the data
17
+ # usually there is no payload - maybe a query if the service accepts it
18
+ def get(path, payload = nil)
19
+ req = Net::HTTP::Get.new(path)
20
+ action(req, payload)
21
+ end
22
+
23
+ # restful post for the given path (like '/users.xml').
24
+ # which creates a new resource or new resources (if the underlying
25
+ # service provides bulk creation)
26
+ def post(path, payload)
27
+ req = Net::HTTP::Post.new(path)
28
+ action(req, payload)
29
+ end
30
+
31
+ # restful put for the given path (like '/users/1.xml').
32
+ # which updates a given resource or many resources (if the underlying
33
+ # service provides bulk updates - path like '/users.xml')
34
+ def put(path, payload)
35
+ req = Net::HTTP::Put.new(path)
36
+ action(req, payload)
37
+ end
38
+
39
+ # restful delete for the given path (like '/users/1.xml').
40
+ # delete a single resource (with no payload) or many resources
41
+ # (if the underlying service provides bulk updates - path like '/users.xml')
42
+ def delete(path, payload = nil)
43
+ req = Net::HTTP::Delete.new(path)
44
+ action(req, payload)
45
+ end
46
+
47
+ private
48
+
49
+ def action(req, payload)
50
+ _action(req, payload)
51
+ rescue NoAuthentiacionError
52
+ # can happen after the session got an idle timeout
53
+ # give it one other trial
54
+ _action(req, payload)
55
+ end
56
+
57
+ def _action(req, payload)
58
+ # authenticate if needed
59
+ unless(@cookie && @token)
60
+ authenticate
61
+ end
62
+
63
+ # setup request with session tracking
64
+ req.content_length = payload.to_s.size
65
+ req.body = payload.to_s
66
+ req['Content-Type'] = 'application/xml'
67
+ req['Authentication-Token'] = @token
68
+ req['Cookie'] = @cookie
69
+
70
+ http = Net::HTTP.new(@host, @port)
71
+ http.read_timeout = 999
72
+
73
+ result = nil
74
+ response = http.start do |h|
75
+ h.request(req) do |response|
76
+ if response.kind_of?(Net::HTTPSuccess)
77
+ # in case there is a new token keep it for the next request
78
+ @token = response['Authentication-Token'] || @token
79
+ # read result
80
+ result = response.read_body
81
+ elsif response.kind_of?(Net::HTTPUnauthorized)
82
+ # clear session tracking data
83
+ @token = nil
84
+ @cookie = nil
85
+ # this exception indicates authentication problem and
86
+ # can trigger retry
87
+ raise NoAuthenticationError.new
88
+ else
89
+ # TODO maybe better error handling
90
+ raise "http error: #{response.inspect}\n\t#{response.body}"
91
+ end
92
+ end
93
+ end
94
+ result
95
+ end
96
+
97
+ def authenticate
98
+ # setup request with authencitation.xml
99
+ req = Net::HTTP::Post.new("/authentication.xml")
100
+ req['Content-Type'] = 'application/xml'
101
+
102
+ # the login payload
103
+ req.body = "<authentication><login>#{@username}</login><password>#{@password}</password></authentication>"
104
+ req.content_length = req.body.size
105
+
106
+ http = Net::HTTP.new(@host, @port)
107
+ http.read_timeout = 999
108
+
109
+ response = http.start do |h|
110
+ h.request(req) do |response|
111
+ if response.kind_of?(Net::HTTPSuccess)
112
+ # read body to close connection - be nice client
113
+ response.read_body
114
+ # keep session tracking info for further request
115
+ @token = response['Authentication-Token']
116
+ # take only the session_id part of the cookie
117
+ @cookie = response['Set-Cookie'].sub(/;.*/, '')
118
+ else
119
+ # TODO maybe better error handling
120
+ raise "http error: #{response.inspect}\n\t#{response.body}"
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
126
+ end
@@ -1,4 +1,3 @@
1
- require 'slf4r'
2
1
  module Ixtlan
3
2
 
4
3
  class UserLogger
@@ -1,3 +1,3 @@
1
1
  class Ixtlan
2
- VERSION = '0.4.0.pre2'.freeze
2
+ VERSION = '0.4.0.pre3'.freeze
3
3
  end
data/lib/models.rb CHANGED
@@ -6,6 +6,7 @@ require 'ixtlan/models'
6
6
  load 'ixtlan/models/authentication.rb'
7
7
  load 'ixtlan/models/user.rb'
8
8
  load 'ixtlan/models/group_locale_user.rb'
9
+ load 'ixtlan/models/domain_group_user.rb'
9
10
  load 'ixtlan/models/group.rb'
10
11
  load 'ixtlan/models/group_user.rb'
11
12
  load 'ixtlan/models/locale.rb'