hypermedia 1.0.9 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/api/model.rb +26 -0
  2. metadata +2 -2
data/lib/api/model.rb CHANGED
@@ -1,6 +1,19 @@
1
1
  # encoding: UTF-8
2
2
 
3
3
  class HypermediaAPI::Model
4
+ def self.auth
5
+ @auth ||= { username: '', password: '' }
6
+ end
7
+
8
+ def self.authorize (username, password)
9
+ @auth = { username: username, password: password }
10
+ end
11
+
12
+ def self.inherited (subclass)
13
+ subclass.authorize(self.auth[:username], self.auth[:password])
14
+ subclass.root_url(@root_url)
15
+ end
16
+
4
17
  def self.new_from_fields (field_elements)
5
18
  instance = self.new
6
19
 
@@ -23,4 +36,17 @@ class HypermediaAPI::Model
23
36
 
24
37
  instance
25
38
  end
39
+
40
+ def self.root_url (url)
41
+ @root_url = url
42
+ end
43
+
44
+ def self.root_doc
45
+ @root_doc ||= HypermediaAPI.get(@root_url, basic_auth: self.auth)
46
+ end
47
+
48
+ def self.query (query_name, form_values)
49
+ query_form = self.root_doc.form("##{query_name.to_s.dasherize}")
50
+ query_form.submit(form_values, basic_auth: self.auth)
51
+ end
26
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hypermedia
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.9
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-06-11 00:00:00.000000000 Z
12
+ date: 2012-07-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport