action_kit_api 0.1.5 → 0.1.6
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.
@@ -1,23 +1,23 @@
|
|
1
1
|
require 'xmlrpc/client'
|
2
2
|
|
3
|
-
# This file adds the connection information for the ActionKit API
|
4
|
-
# which is used throughout the rest of the Gem (a connection being
|
5
|
-
# required for ... well every operation ... this is a remote API
|
6
|
-
# gem :)
|
7
|
-
|
8
|
-
# This seems silly and dangerous right? Overwriting something in the ruby
|
9
|
-
# standard libraries? Well ActionKit is doing XMLRPC wrong. This is almost
|
10
|
-
# identical to the Ruby standard library version however it drops the type
|
11
|
-
# check on the faultCode and the faultString. The XMLRPC standard indicates
|
12
|
-
# that yes the faultCode has to be an integer and faultString has to be a
|
13
|
-
# string. ActionKit WILL RETURN A STRING AS THE faultCode.
|
14
|
-
#
|
15
|
-
# References:
|
16
|
-
# XMLRPC Spec:
|
17
|
-
# http://xmlrpc.scripting.com/spec.html
|
18
|
-
# ActionKit (just an example, see second sentence under 'get'
|
19
|
-
# https://roboticdogs.actionkit.com/docs/manual/api/users.html?highlight=faultcode
|
20
3
|
module XMLRPC
|
4
|
+
# This file adds the connection information for the ActionKit API
|
5
|
+
# which is used throughout the rest of the Gem (a connection being
|
6
|
+
# required for ... well every operation ... this is a remote API
|
7
|
+
# gem :)
|
8
|
+
|
9
|
+
# This seems silly and dangerous right? Overwriting something in the ruby
|
10
|
+
# standard libraries? Well ActionKit is doing XMLRPC wrong. This is almost
|
11
|
+
# identical to the Ruby standard library version however it drops the type
|
12
|
+
# check on the faultCode and the faultString. The XMLRPC standard indicates
|
13
|
+
# that yes the faultCode has to be an integer and faultString has to be a
|
14
|
+
# string. ActionKit WILL RETURN A STRING AS THE faultCode.
|
15
|
+
#
|
16
|
+
# References:
|
17
|
+
# XMLRPC Spec:
|
18
|
+
# http://xmlrpc.scripting.com/spec.html
|
19
|
+
# ActionKit (just an example, see second sentence under 'get'
|
20
|
+
# https://roboticdogs.actionkit.com/docs/manual/api/users.html?highlight=faultcode
|
21
21
|
module Convert
|
22
22
|
def self.fault(hash)
|
23
23
|
if hash.kind_of? Hash and hash.size == 2 and
|
@@ -29,6 +29,13 @@ module XMLRPC
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
# We're overriding the user agent to make these requests more obviously
|
34
|
+
# from this wrapper
|
35
|
+
class Client
|
36
|
+
remove_const(:USER_AGENT)
|
37
|
+
USER_AGENT = "DFA Ruby action_kit_api/#{ActionKitApi::VERSION} ( http://code.democracyforamerica.com/ )"
|
38
|
+
end
|
32
39
|
end
|
33
40
|
|
34
41
|
module ActionKitApi
|
@@ -69,13 +76,10 @@ module ActionKitApi
|
|
69
76
|
raise NoConnection if @@connection.nil?
|
70
77
|
|
71
78
|
# XMLRPC::Client doesn't flush it's IO buffer which occasionally
|
72
|
-
# causes a second command
|
73
|
-
#
|
74
|
-
|
75
|
-
|
76
|
-
rescue EOFError
|
77
|
-
@@connection.call(command, args)
|
78
|
-
end
|
79
|
+
# causes a second command on the same connection to fail with an
|
80
|
+
# EOFError. Using the _async version of this causes XMLRPC::Client
|
81
|
+
# to use a new connection each time eliminating this issue
|
82
|
+
@@connection.call_async(command, args)
|
79
83
|
end
|
80
84
|
|
81
85
|
def self.version
|
@@ -5,7 +5,6 @@ module ActionKitApi
|
|
5
5
|
end
|
6
6
|
|
7
7
|
class ApiDataModel
|
8
|
-
|
9
8
|
def initialize(hash = {})
|
10
9
|
@required_attrs = []
|
11
10
|
|
@@ -57,6 +56,11 @@ module ActionKitApi
|
|
57
56
|
user_hash[key] = self.instance_variable_get(iv)
|
58
57
|
end
|
59
58
|
|
59
|
+
# XMLRPC::Client doesn't like empty values
|
60
|
+
user_hash.delete_if do |k, v|
|
61
|
+
v.to_s.empty?
|
62
|
+
end
|
63
|
+
|
60
64
|
user_hash
|
61
65
|
end
|
62
66
|
end
|
@@ -22,7 +22,7 @@ module ActionKitApi
|
|
22
22
|
# Get the name of the class that this module has been mixed into
|
23
23
|
class_name = self.to_s.split("::").last
|
24
24
|
|
25
|
-
search = parse_attributes(attrs, args)
|
25
|
+
search = self.parse_attributes(attrs, args)
|
26
26
|
|
27
27
|
begin
|
28
28
|
response = ActionKitApi::Connection.call("#{class_name}.get", search)
|
@@ -48,11 +48,11 @@ module ActionKitApi
|
|
48
48
|
# Get the name of the class that this module has been mixed into
|
49
49
|
class_name = self.to_s.split("::").last
|
50
50
|
|
51
|
-
search = parse_attributes(attrs, args)
|
51
|
+
search = self.parse_attributes(attrs, args)
|
52
52
|
|
53
53
|
# For when I get to retrieving all results, through pagination
|
54
54
|
# Would be a good candidate for yielding (probably in batches of 50-100)
|
55
|
-
#response_count =
|
55
|
+
#response_count = self.count(search)
|
56
56
|
search["limit"] = 1000
|
57
57
|
#search["offset"] = 0
|
58
58
|
|
@@ -66,6 +66,10 @@ module ActionKitApi
|
|
66
66
|
response_objects
|
67
67
|
end
|
68
68
|
|
69
|
+
def class_name.count(search)
|
70
|
+
ActionKitApi::Connection.call("#{class_name}.count", search)
|
71
|
+
end
|
72
|
+
|
69
73
|
# Helper method for method_missing and the find_* virtual methods that
|
70
74
|
# parses part of a method name and arguments into a hash usuable for the
|
71
75
|
# API calls
|
data/lib/action_kit_api.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 6
|
9
|
+
version: 0.1.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Sam Stelfox
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2012-02-
|
17
|
+
date: 2012-02-24 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|