yast 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +5 -0
- data/Rakefile +1 -0
- data/lib/yast.rb +150 -0
- data/lib/yast/version.rb +3 -0
- data/yast.gemspec +24 -0
- metadata +76 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
This gem will allow you to connect to the http://www.yast.com API.
|
2
|
+
|
3
|
+
This is just a first release and all you can do now is log in, get folders, get projects, and get records.
|
4
|
+
|
5
|
+
I haven't added any tests yet, as I'm not sure how to do that agains an API that requires login.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/lib/yast.rb
ADDED
@@ -0,0 +1,150 @@
|
|
1
|
+
require "yast/version"
|
2
|
+
require "builder"
|
3
|
+
require "net/http"
|
4
|
+
require "xmlsimple"
|
5
|
+
|
6
|
+
module Yast
|
7
|
+
mattr_accessor :username, :password, :hash,
|
8
|
+
:timefrom, :timeto, :typeid, :parentid
|
9
|
+
|
10
|
+
|
11
|
+
class Record
|
12
|
+
attr_accessor :id, :typeId, :timeCreated, :timeUpdated, :project,
|
13
|
+
:creator, :flags, :startTime, :endTime, :comment,
|
14
|
+
:isRunning, :phoneNumber, :outgoing
|
15
|
+
end
|
16
|
+
|
17
|
+
class Project
|
18
|
+
attr_accessor :id, :name, :description, :primaryColor, :parentId,
|
19
|
+
:privileges, :timeCreated, :creator
|
20
|
+
end
|
21
|
+
|
22
|
+
class Folder
|
23
|
+
attr_accessor :id, :name, :description, :primaryColor, :parentId,
|
24
|
+
:privileges, :timeCreated, :creator
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
def self.login
|
29
|
+
unless username.nil? or password.nil?
|
30
|
+
xml_string = generate_request('auth.login', {:user => username, :password => password})
|
31
|
+
xml = get_xml(xml_string)
|
32
|
+
self.hash = xml['hash'].first if xml.has_key? ('hash')
|
33
|
+
end
|
34
|
+
|
35
|
+
return !self.hash.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.get_xml(xml_string)
|
39
|
+
url = URI.parse( "http://www.yast.com/1.0/" )
|
40
|
+
|
41
|
+
response = Net::HTTP.start(url.host, url.port) do |http|
|
42
|
+
http.post("http://www.yast.com/1.0/", "request=#{xml_string}")
|
43
|
+
end
|
44
|
+
XmlSimple.xml_in(response.body)
|
45
|
+
end
|
46
|
+
|
47
|
+
def self.generate_request(request, list)
|
48
|
+
target_object = ''
|
49
|
+
xml = Builder::XmlMarkup.new( :target => target_object, :indent => 2 )
|
50
|
+
|
51
|
+
xml.instruct! :xml
|
52
|
+
xml.request('req' => request, 'id' => 133) do |b|
|
53
|
+
list.each do |k, v|
|
54
|
+
b.tag!( k, v)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
target_object
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
def self.get_records
|
62
|
+
records = []
|
63
|
+
unless username.nil? or hash.nil?
|
64
|
+
request_hash = { :user => username, :hash => hash }
|
65
|
+
request_hash['timeFrom'] = timefrom if timefrom
|
66
|
+
request_hash['timeTo'] = timefrom if timeto
|
67
|
+
request_hash['typeId'] = typeid if typeid
|
68
|
+
request_hash['parentId'] = parentid if parentid
|
69
|
+
|
70
|
+
xml_string = generate_request('data.getRecords', request_hash)
|
71
|
+
xml = get_xml(xml_string)
|
72
|
+
|
73
|
+
unless xml['objects'][0]['record'].nil?
|
74
|
+
xml['objects'][0]['record'].each do |record|
|
75
|
+
puts record.to_json
|
76
|
+
r = Yast::Record.new
|
77
|
+
|
78
|
+
r.id = record['id']
|
79
|
+
r.typeId = record['typeId']
|
80
|
+
r.timeCreated = Time.at(record['timeCreated'][0].to_i)
|
81
|
+
r.timeUpdated = Time.at(record['timeUpdated'][0].to_i)
|
82
|
+
r.project = record['project']
|
83
|
+
r.startTime = Time.at(record['variables'][0]['v'][0].to_i)
|
84
|
+
r.endTime = Time.at(record['variables'][0]['v'][1].to_i)
|
85
|
+
r.comment = record['variables'][0]['v'][2]
|
86
|
+
r.isRunning = record['variables'][0]['v'][3] == 1
|
87
|
+
r.phoneNumber = record['variables'][0]['v'][4]
|
88
|
+
r.outgoing = record['variables'][0]['v'][5] == 1
|
89
|
+
|
90
|
+
records << r
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
records
|
95
|
+
end
|
96
|
+
|
97
|
+
def self.get_projects
|
98
|
+
projects = []
|
99
|
+
|
100
|
+
unless username.nil? or hash.nil?
|
101
|
+
xml_string = generate_request( 'data.getProjects', {:user => username, :hash => hash} )
|
102
|
+
xml = get_xml(xml_string)
|
103
|
+
|
104
|
+
unless xml['objects'][0]['project'].nil?
|
105
|
+
xml['objects'][0]['project'].each do |project|
|
106
|
+
p = Yast::Project.new
|
107
|
+
|
108
|
+
p.id = project['id']
|
109
|
+
p.name = project['name']
|
110
|
+
p.description = project['description']
|
111
|
+
p.primaryColor = project['primaryColor']
|
112
|
+
p.parentId = project['parentId']
|
113
|
+
p.privileges = project['privileges']
|
114
|
+
p.timeCreated = Time.at(project['timeCreated'][0].to_i)
|
115
|
+
p.creator = project['creator']
|
116
|
+
|
117
|
+
projects << p
|
118
|
+
end
|
119
|
+
end
|
120
|
+
end
|
121
|
+
projects
|
122
|
+
end
|
123
|
+
|
124
|
+
def self.get_folders
|
125
|
+
folders = []
|
126
|
+
|
127
|
+
unless username.nil? or hash.nil?
|
128
|
+
xml_string = generate_request( 'data.getFolders', {:user => username, :hash => hash} )
|
129
|
+
xml = get_xml(xml_string)
|
130
|
+
|
131
|
+
unless xml['objects'][0]['folder'].nil?
|
132
|
+
xml['objects'][0]['folder'].each do |folder|
|
133
|
+
p = Yast::Project.new
|
134
|
+
|
135
|
+
p.id = folder['id']
|
136
|
+
p.name = folder['name']
|
137
|
+
p.description = folder['description']
|
138
|
+
p.primaryColor = folder['primaryColor']
|
139
|
+
p.parentId = folder['parentId']
|
140
|
+
p.privileges = folder['privileges']
|
141
|
+
p.timeCreated = Time.at(folder['timeCreated'][0].to_i)
|
142
|
+
p.creator = folder['creator']
|
143
|
+
|
144
|
+
folders << p
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
folders
|
149
|
+
end
|
150
|
+
end
|
data/lib/yast/version.rb
ADDED
data/yast.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "yast/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "yast"
|
7
|
+
s.version = Yast::VERSION
|
8
|
+
s.authors = ["Thomas Smestad"]
|
9
|
+
s.email = ["smestad.thomas@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{API to http://www-yast.com}
|
12
|
+
s.description = %q{Gem to use Yast API}
|
13
|
+
|
14
|
+
s.rubyforge_project = "yast"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
s.add_dependency('builder')
|
22
|
+
s.add_dependency('xml-simple')
|
23
|
+
# s.add_dependency('net/http')
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yast
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Thomas Smestad
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-17 00:00:00.000000000 +01:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: builder
|
17
|
+
requirement: &18839500 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *18839500
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: xml-simple
|
28
|
+
requirement: &18838960 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *18838960
|
37
|
+
description: Gem to use Yast API
|
38
|
+
email:
|
39
|
+
- smestad.thomas@gmail.com
|
40
|
+
executables: []
|
41
|
+
extensions: []
|
42
|
+
extra_rdoc_files: []
|
43
|
+
files:
|
44
|
+
- .gitignore
|
45
|
+
- Gemfile
|
46
|
+
- README.markdown
|
47
|
+
- Rakefile
|
48
|
+
- lib/yast.rb
|
49
|
+
- lib/yast/version.rb
|
50
|
+
- yast.gemspec
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: ''
|
53
|
+
licenses: []
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
require_paths:
|
57
|
+
- lib
|
58
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
requirements: []
|
71
|
+
rubyforge_project: yast
|
72
|
+
rubygems_version: 1.6.2
|
73
|
+
signing_key:
|
74
|
+
specification_version: 3
|
75
|
+
summary: API to http://www-yast.com
|
76
|
+
test_files: []
|