Module: Yast
- Defined in:
- lib/yast.rb,
lib/yast/version.rb
Defined Under Namespace
Classes: Folder, Project, Record
Constant Summary
collapse
- VERSION =
"0.0.1"
Class Method Summary
collapse
Class Method Details
.generate_request(request, list) ⇒ Object
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/yast.rb', line 47
def self.generate_request(request, list)
target_object = ''
xml = Builder::XmlMarkup.new( :target => target_object, :indent => 2 )
xml.instruct! :xml
xml.request('req' => request, 'id' => 133) do |b|
list.each do |k, v|
b.tag!( k, v)
end
end
target_object
end
|
.get_folders ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
# File 'lib/yast.rb', line 124
def self.get_folders
folders = []
unless username.nil? or hash.nil?
xml_string = generate_request( 'data.getFolders', {:user => username, :hash => hash} )
xml = get_xml(xml_string)
unless xml['objects'][0]['folder'].nil?
xml['objects'][0]['folder'].each do |folder|
p = Yast::Project.new
p.id = folder['id']
p.name = folder['name']
p.description = folder['description']
p.primaryColor = folder['primaryColor']
p.parentId = folder['parentId']
p.privileges = folder['privileges']
p.timeCreated = Time.at(folder['timeCreated'][0].to_i)
p.creator = folder['creator']
folders << p
end
end
end
folders
end
|
.get_projects ⇒ Object
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/yast.rb', line 97
def self.get_projects
projects = []
unless username.nil? or hash.nil?
xml_string = generate_request( 'data.getProjects', {:user => username, :hash => hash} )
xml = get_xml(xml_string)
unless xml['objects'][0]['project'].nil?
xml['objects'][0]['project'].each do |project|
p = Yast::Project.new
p.id = project['id']
p.name = project['name']
p.description = project['description']
p.primaryColor = project['primaryColor']
p.parentId = project['parentId']
p.privileges = project['privileges']
p.timeCreated = Time.at(project['timeCreated'][0].to_i)
p.creator = project['creator']
projects << p
end
end
end
projects
end
|
.get_records ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
# File 'lib/yast.rb', line 61
def self.get_records
records = []
unless username.nil? or hash.nil?
request_hash = { :user => username, :hash => hash }
request_hash['timeFrom'] = timefrom if timefrom
request_hash['timeTo'] = timefrom if timeto
request_hash['typeId'] = typeid if typeid
request_hash['parentId'] = parentid if parentid
xml_string = generate_request('data.getRecords', request_hash)
xml = get_xml(xml_string)
unless xml['objects'][0]['record'].nil?
xml['objects'][0]['record'].each do |record|
puts record.to_json
r = Yast::Record.new
r.id = record['id']
r.typeId = record['typeId']
r.timeCreated = Time.at(record['timeCreated'][0].to_i)
r.timeUpdated = Time.at(record['timeUpdated'][0].to_i)
r.project = record['project']
r.startTime = Time.at(record['variables'][0]['v'][0].to_i)
r.endTime = Time.at(record['variables'][0]['v'][1].to_i)
r. = record['variables'][0]['v'][2]
r.isRunning = record['variables'][0]['v'][3] == 1
r.phoneNumber = record['variables'][0]['v'][4]
r.outgoing = record['variables'][0]['v'][5] == 1
records << r
end
end
end
records
end
|
.get_xml(xml_string) ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/yast.rb', line 38
def self.get_xml(xml_string)
url = URI.parse( "http://www.yast.com/1.0/" )
response = Net::HTTP.start(url.host, url.port) do |http|
http.post("http://www.yast.com/1.0/", "request=#{xml_string}")
end
XmlSimple.xml_in(response.body)
end
|
.login ⇒ Object
28
29
30
31
32
33
34
35
36
|
# File 'lib/yast.rb', line 28
def self.login
unless username.nil? or password.nil?
xml_string = generate_request('auth.login', {:user => username, :password => password})
xml = get_xml(xml_string)
self.hash = xml['hash'].first if xml.has_key? ('hash')
end
return !self.hash.nil?
end
|