Module: Iftttify
- Defined in:
- lib/iftttify.rb,
lib/iftttify/version.rb,
lib/iftttify/iftttify.rb,
lib/iftttify/exceptions.rb
Defined Under Namespace
Modules: ActAsIFTTT, Exceptions
Classes: Post
Constant Summary
collapse
- VERSION =
"0.0.1"
Class Method Summary
collapse
Class Method Details
.members_to_hash(members) ⇒ Object
37
38
39
40
41
42
43
44
45
|
# File 'lib/iftttify/iftttify.rb', line 37
def self.members_to_hash(members)
h = Hash.new
members.each do |kv|
if kv["value"]["string"]
h[kv["name"].to_sym] = kv["value"]["string"]
end
end
h
end
|
.process(request, options, &block) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/iftttify/iftttify.rb', line 6
def self.process(request, options, &block)
r = Hash.from_xml(request.body.read)
methodName = r["methodCall"]["methodName"]
if methodName == 'mt.supportedMethods'
'metaWeblog.getRecentPosts'
elsif methodName == 'metaWeblog.getRecentPosts'
'<array><data></data></array>'
elsif methodName == 'metaWeblog.newPost'
username = r["methodCall"]["params"]["param"][1]["value"]["string"]
password = r["methodCall"]["params"]["param"][2]["value"]["string"]
if !options[:auth] || (options[:auth][:username] == username) && (options[:auth][:password] == password)
h = Iftttify::members_to_hash(r["methodCall"]["params"]["param"][3]["value"]["struct"]["member"])
result = block.call Post.new(
r["methodCall"]["params"]["param"][0]["value"]["string"],
username,
password,
h[:title],
h[:description]
)
result
else
raise Iftttify::Exceptions::InvalidCredential, "Failed to verify credential provided: [#{username}] with [#{password}]"
end
else
raise Iftttify::Exceptions::InvalidMethod, "Failed to recognize #{methodName}"
end
end
|