impermium 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. data/.gitignore +5 -0
  2. data/.rspec +1 -0
  3. data/.rvmrc +1 -0
  4. data/Gemfile +4 -0
  5. data/MIT-LICENSE.txt +20 -0
  6. data/README.md +118 -0
  7. data/Rakefile +7 -0
  8. data/impermium.gemspec +31 -0
  9. data/lib/faraday/raise_4xx.rb +18 -0
  10. data/lib/impermium/client.rb +57 -0
  11. data/lib/impermium/configuration.rb +44 -0
  12. data/lib/impermium/content/blog_post.rb +38 -0
  13. data/lib/impermium/content/bookmark.rb +47 -0
  14. data/lib/impermium/content/comment.rb +38 -0
  15. data/lib/impermium/content/connection.rb +42 -0
  16. data/lib/impermium/content/listing.rb +37 -0
  17. data/lib/impermium/content.rb +15 -0
  18. data/lib/impermium/errors.rb +25 -0
  19. data/lib/impermium/user/account.rb +50 -0
  20. data/lib/impermium/user/profile.rb +35 -0
  21. data/lib/impermium/user.rb +9 -0
  22. data/lib/impermium/version.rb +3 -0
  23. data/lib/impermium.rb +20 -0
  24. data/spec/.gitignore +1 -0
  25. data/spec/cassettes/content_API_section/blog_post_object/blog_post_analyst_feedback_method/missing_arguments/missing_analyst_id.yml +42 -0
  26. data/spec/cassettes/content_API_section/blog_post_object/blog_post_analyst_feedback_method/missing_arguments/missing_blog_post_id.yml +42 -0
  27. data/spec/cassettes/content_API_section/blog_post_object/blog_post_analyst_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  28. data/spec/cassettes/content_API_section/blog_post_object/blog_post_analyst_feedback_method/successful_request.yml +38 -0
  29. data/spec/cassettes/content_API_section/blog_post_object/blog_post_method/missing_arguments/missing_blog_post_id.yml +43 -0
  30. data/spec/cassettes/content_API_section/blog_post_object/blog_post_method/missing_arguments/missing_blog_post_permalink.yml +43 -0
  31. data/spec/cassettes/content_API_section/blog_post_object/blog_post_method/missing_arguments/missing_blog_url.yml +43 -0
  32. data/spec/cassettes/content_API_section/blog_post_object/blog_post_method/missing_arguments/missing_content.yml +42 -0
  33. data/spec/cassettes/content_API_section/blog_post_object/blog_post_method/missing_arguments/missing_enduser_ip.yml +43 -0
  34. data/spec/cassettes/content_API_section/blog_post_object/blog_post_method/missing_arguments/missing_user_id.yml +43 -0
  35. data/spec/cassettes/content_API_section/blog_post_object/blog_post_method/successful_blog_post_request.yml +39 -0
  36. data/spec/cassettes/content_API_section/blog_post_object/blog_post_user_feedback_method/missing_arguments/invalid_reporter_user_type.yml +38 -0
  37. data/spec/cassettes/content_API_section/blog_post_object/blog_post_user_feedback_method/missing_arguments/missing_blog_post_id.yml +42 -0
  38. data/spec/cassettes/content_API_section/blog_post_object/blog_post_user_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  39. data/spec/cassettes/content_API_section/blog_post_object/blog_post_user_feedback_method/missing_arguments/missing_reporter_ip.yml +42 -0
  40. data/spec/cassettes/content_API_section/blog_post_object/blog_post_user_feedback_method/missing_arguments/missing_reporter_user_id.yml +42 -0
  41. data/spec/cassettes/content_API_section/blog_post_object/blog_post_user_feedback_method/successful_request.yml +38 -0
  42. data/spec/cassettes/content_API_section/bookmark_object/bookmark_analyst_feedback_method/missing_arguments/missing_analyst_id.yml +42 -0
  43. data/spec/cassettes/content_API_section/bookmark_object/bookmark_analyst_feedback_method/missing_arguments/missing_bookmark_id.yml +42 -0
  44. data/spec/cassettes/content_API_section/bookmark_object/bookmark_analyst_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  45. data/spec/cassettes/content_API_section/bookmark_object/bookmark_analyst_feedback_method/successful_request.yml +38 -0
  46. data/spec/cassettes/content_API_section/bookmark_object/bookmark_like_method/missing_arguments/missing_bookmark_id.yml +42 -0
  47. data/spec/cassettes/content_API_section/bookmark_object/bookmark_like_method/missing_arguments/missing_bookmark_url.yml +42 -0
  48. data/spec/cassettes/content_API_section/bookmark_object/bookmark_like_method/missing_arguments/missing_enduser_ip.yml +42 -0
  49. data/spec/cassettes/content_API_section/bookmark_object/bookmark_like_method/missing_arguments/missing_like_value.yml +42 -0
  50. data/spec/cassettes/content_API_section/bookmark_object/bookmark_like_method/missing_arguments/missing_user_id.yml +42 -0
  51. data/spec/cassettes/content_API_section/bookmark_object/bookmark_like_method/successful_request.yml +38 -0
  52. data/spec/cassettes/content_API_section/bookmark_object/bookmark_method/missing_arguments/missing_bookmark_id.yml +42 -0
  53. data/spec/cassettes/content_API_section/bookmark_object/bookmark_method/missing_arguments/missing_bookmark_url.yml +42 -0
  54. data/spec/cassettes/content_API_section/bookmark_object/bookmark_method/missing_arguments/missing_enduser_ip.yml +42 -0
  55. data/spec/cassettes/content_API_section/bookmark_object/bookmark_method/missing_arguments/missing_user_id.yml +42 -0
  56. data/spec/cassettes/content_API_section/bookmark_object/bookmark_method/successful_request.yml +38 -0
  57. data/spec/cassettes/content_API_section/bookmark_object/bookmark_user_feedback_method/missing_arguments/invalid_reporter_user_type.yml +38 -0
  58. data/spec/cassettes/content_API_section/bookmark_object/bookmark_user_feedback_method/missing_arguments/missing_bookmark_id.yml +42 -0
  59. data/spec/cassettes/content_API_section/bookmark_object/bookmark_user_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  60. data/spec/cassettes/content_API_section/bookmark_object/bookmark_user_feedback_method/missing_arguments/missing_reporter_ip.yml +42 -0
  61. data/spec/cassettes/content_API_section/bookmark_object/bookmark_user_feedback_method/missing_arguments/missing_reporter_user_id.yml +42 -0
  62. data/spec/cassettes/content_API_section/bookmark_object/bookmark_user_feedback_method/successful_request.yml +38 -0
  63. data/spec/cassettes/content_API_section/comment_object/comment_analyst_feedback_method/missing_arguments/missing_analyst_id.yml +42 -0
  64. data/spec/cassettes/content_API_section/comment_object/comment_analyst_feedback_method/missing_arguments/missing_comment_id.yml +42 -0
  65. data/spec/cassettes/content_API_section/comment_object/comment_analyst_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  66. data/spec/cassettes/content_API_section/comment_object/comment_analyst_feedback_method/successful_request.yml +38 -0
  67. data/spec/cassettes/content_API_section/comment_object/comment_method/missing_arguments/missing_article_permalink.yml +43 -0
  68. data/spec/cassettes/content_API_section/comment_object/comment_method/missing_arguments/missing_comment_id.yml +42 -0
  69. data/spec/cassettes/content_API_section/comment_object/comment_method/missing_arguments/missing_comment_permalink.yml +43 -0
  70. data/spec/cassettes/content_API_section/comment_object/comment_method/missing_arguments/missing_content.yml +42 -0
  71. data/spec/cassettes/content_API_section/comment_object/comment_method/missing_arguments/missing_enduser_ip.yml +43 -0
  72. data/spec/cassettes/content_API_section/comment_object/comment_method/missing_arguments/missing_user_id.yml +43 -0
  73. data/spec/cassettes/content_API_section/comment_object/comment_method/successful_request.yml +39 -0
  74. data/spec/cassettes/content_API_section/comment_object/comment_user_feedback_method/missing_arguments/invalid_reporter_user_type.yml +38 -0
  75. data/spec/cassettes/content_API_section/comment_object/comment_user_feedback_method/missing_arguments/missing_comment_id.yml +42 -0
  76. data/spec/cassettes/content_API_section/comment_object/comment_user_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  77. data/spec/cassettes/content_API_section/comment_object/comment_user_feedback_method/missing_arguments/missing_reporter_ip.yml +42 -0
  78. data/spec/cassettes/content_API_section/comment_object/comment_user_feedback_method/missing_arguments/missing_reporter_user_id.yml +42 -0
  79. data/spec/cassettes/content_API_section/comment_object/comment_user_feedback_method/successful_request.yml +38 -0
  80. data/spec/cassettes/content_API_section/connection_object/connection_analyst_feedback_method/missing_arguments/invalid_connection_type_value.yml +42 -0
  81. data/spec/cassettes/content_API_section/connection_object/connection_analyst_feedback_method/missing_arguments/missing_analyst_id.yml +42 -0
  82. data/spec/cassettes/content_API_section/connection_object/connection_analyst_feedback_method/missing_arguments/missing_connection_id.yml +42 -0
  83. data/spec/cassettes/content_API_section/connection_object/connection_analyst_feedback_method/missing_arguments/missing_connection_type.yml +42 -0
  84. data/spec/cassettes/content_API_section/connection_object/connection_analyst_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  85. data/spec/cassettes/content_API_section/connection_object/connection_analyst_feedback_method/successful_request.yml +38 -0
  86. data/spec/cassettes/content_API_section/connection_object/connection_method/missing_arguments/invalid_connection_type_value.yml +42 -0
  87. data/spec/cassettes/content_API_section/connection_object/connection_method/missing_arguments/invalid_operation_value.yml +38 -0
  88. data/spec/cassettes/content_API_section/connection_object/connection_method/missing_arguments/missing_connection_id.yml +42 -0
  89. data/spec/cassettes/content_API_section/connection_object/connection_method/missing_arguments/missing_connection_type.yml +42 -0
  90. data/spec/cassettes/content_API_section/connection_object/connection_method/missing_arguments/missing_enduser_ip.yml +42 -0
  91. data/spec/cassettes/content_API_section/connection_object/connection_method/missing_arguments/missing_requester_user_id.yml +42 -0
  92. data/spec/cassettes/content_API_section/connection_object/connection_method/missing_arguments/missing_responder_user_id.yml +42 -0
  93. data/spec/cassettes/content_API_section/connection_object/connection_method/successful_follow_connection_request.yml +38 -0
  94. data/spec/cassettes/content_API_section/connection_object/connection_method/successful_follow_connection_response.yml +38 -0
  95. data/spec/cassettes/content_API_section/connection_object/connection_method/successful_friend_connection_request.yml +38 -0
  96. data/spec/cassettes/content_API_section/connection_object/connection_method/successful_friend_connection_response.yml +38 -0
  97. data/spec/cassettes/content_API_section/connection_object/connection_user_feedback_method/missing_arguments/invalid_connection_type_value.yml +42 -0
  98. data/spec/cassettes/content_API_section/connection_object/connection_user_feedback_method/missing_arguments/invalid_reporter_user_type.yml +38 -0
  99. data/spec/cassettes/content_API_section/connection_object/connection_user_feedback_method/missing_arguments/missing_connection_id.yml +42 -0
  100. data/spec/cassettes/content_API_section/connection_object/connection_user_feedback_method/missing_arguments/missing_connection_type.yml +42 -0
  101. data/spec/cassettes/content_API_section/connection_object/connection_user_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  102. data/spec/cassettes/content_API_section/connection_object/connection_user_feedback_method/missing_arguments/missing_reporter_ip.yml +42 -0
  103. data/spec/cassettes/content_API_section/connection_object/connection_user_feedback_method/missing_arguments/missing_reporter_user_id.yml +42 -0
  104. data/spec/cassettes/content_API_section/connection_object/connection_user_feedback_method/successful_request.yml +38 -0
  105. data/spec/cassettes/content_API_section/listing_object/listing_analyst_feedback_method/missing_arguments/missing_analyst_id.yml +42 -0
  106. data/spec/cassettes/content_API_section/listing_object/listing_analyst_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  107. data/spec/cassettes/content_API_section/listing_object/listing_analyst_feedback_method/missing_arguments/missing_listing_id.yml +42 -0
  108. data/spec/cassettes/content_API_section/listing_object/listing_analyst_feedback_method/successful_request.yml +38 -0
  109. data/spec/cassettes/content_API_section/listing_object/listing_method/missing_arguments/missing_content.yml +42 -0
  110. data/spec/cassettes/content_API_section/listing_object/listing_method/missing_arguments/missing_enduser_ip.yml +42 -0
  111. data/spec/cassettes/content_API_section/listing_object/listing_method/missing_arguments/missing_listing_id.yml +42 -0
  112. data/spec/cassettes/content_API_section/listing_object/listing_method/missing_arguments/missing_listing_permalink.yml +42 -0
  113. data/spec/cassettes/content_API_section/listing_object/listing_method/missing_arguments/missing_user_id.yml +42 -0
  114. data/spec/cassettes/content_API_section/listing_object/listing_method/successful_request.yml +38 -0
  115. data/spec/cassettes/content_API_section/listing_object/listing_user_feedback_method/missing_arguments/invalid_reporter_user_type.yml +38 -0
  116. data/spec/cassettes/content_API_section/listing_object/listing_user_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  117. data/spec/cassettes/content_API_section/listing_object/listing_user_feedback_method/missing_arguments/missing_listing_id.yml +42 -0
  118. data/spec/cassettes/content_API_section/listing_object/listing_user_feedback_method/missing_arguments/missing_reporter_ip.yml +42 -0
  119. data/spec/cassettes/content_API_section/listing_object/listing_user_feedback_method/missing_arguments/missing_reporter_user_id.yml +42 -0
  120. data/spec/cassettes/content_API_section/listing_object/listing_user_feedback_method/successful_request.yml +38 -0
  121. data/spec/cassettes/user_API_section/account_object/account_analyst_feedback_method/missing_arguments/missing_analyst_id.yml +42 -0
  122. data/spec/cassettes/user_API_section/account_object/account_analyst_feedback_method/missing_arguments/missing_user_id.yml +42 -0
  123. data/spec/cassettes/user_API_section/account_object/account_analyst_feedback_method/successful_account_analyst_feedback_method_request.yml +38 -0
  124. data/spec/cassettes/user_API_section/account_object/account_attempt_method/missing_arguments.yml +42 -0
  125. data/spec/cassettes/user_API_section/account_object/account_attempt_method/successful_account_attempt_request.yml +38 -0
  126. data/spec/cassettes/user_API_section/account_object/account_login_method/missing_arguments/missing_enduser_ip.yml +42 -0
  127. data/spec/cassettes/user_API_section/account_object/account_login_method/missing_arguments/missing_user_id.yml +42 -0
  128. data/spec/cassettes/user_API_section/account_object/account_login_method/successful_account_login_request.yml +38 -0
  129. data/spec/cassettes/user_API_section/account_object/account_method/missing_arguments/missing_enduser_ip.yml +42 -0
  130. data/spec/cassettes/user_API_section/account_object/account_method/missing_arguments/missing_user_id.yml +42 -0
  131. data/spec/cassettes/user_API_section/account_object/account_method/successful_account_method_request.yml +38 -0
  132. data/spec/cassettes/user_API_section/account_object/account_user_feedback_method/missing_arguments/invalid_reporter_user_type.yml +38 -0
  133. data/spec/cassettes/user_API_section/account_object/account_user_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  134. data/spec/cassettes/user_API_section/account_object/account_user_feedback_method/missing_arguments/missing_reporter_ip.yml +42 -0
  135. data/spec/cassettes/user_API_section/account_object/account_user_feedback_method/missing_arguments/missing_reporter_user_id.yml +42 -0
  136. data/spec/cassettes/user_API_section/account_object/account_user_feedback_method/missing_arguments/missing_user_id.yml +42 -0
  137. data/spec/cassettes/user_API_section/account_object/account_user_feedback_method/successful_request.yml +38 -0
  138. data/spec/cassettes/user_API_section/profile_object/profile_analyst_feedback_method/missing_params/missing_analyst_id.yml +42 -0
  139. data/spec/cassettes/user_API_section/profile_object/profile_analyst_feedback_method/missing_params/missing_desired_result.yml +42 -0
  140. data/spec/cassettes/user_API_section/profile_object/profile_analyst_feedback_method/missing_params/missing_profile_id.yml +42 -0
  141. data/spec/cassettes/user_API_section/profile_object/profile_analyst_feedback_method/successful_request.yml +38 -0
  142. data/spec/cassettes/user_API_section/profile_object/profile_method/missing_arguments/missing_enduser_ip.yml +42 -0
  143. data/spec/cassettes/user_API_section/profile_object/profile_method/missing_arguments/missing_profile_id.yml +42 -0
  144. data/spec/cassettes/user_API_section/profile_object/profile_method/missing_arguments/missing_user_id.yml +42 -0
  145. data/spec/cassettes/user_API_section/profile_object/profile_method/successful_request.yml +38 -0
  146. data/spec/cassettes/user_API_section/profile_object/profile_user_feedback_method/missing_arguments/invalid_reporter_user_type.yml +38 -0
  147. data/spec/cassettes/user_API_section/profile_object/profile_user_feedback_method/missing_arguments/missing_desired_result.yml +42 -0
  148. data/spec/cassettes/user_API_section/profile_object/profile_user_feedback_method/missing_arguments/missing_profile_id.yml +42 -0
  149. data/spec/cassettes/user_API_section/profile_object/profile_user_feedback_method/missing_arguments/missing_reporter_ip.yml +42 -0
  150. data/spec/cassettes/user_API_section/profile_object/profile_user_feedback_method/missing_arguments/missing_reporter_user_id.yml +42 -0
  151. data/spec/cassettes/user_API_section/profile_object/profile_user_feedback_method/successful_request.yml +38 -0
  152. data/spec/configuration.yml.sample +3 -0
  153. data/spec/impermium/client_spec.rb +67 -0
  154. data/spec/impermium/content/blog_post_spec.rb +173 -0
  155. data/spec/impermium/content/bookmark_spec.rb +205 -0
  156. data/spec/impermium/content/comment_spec.rb +178 -0
  157. data/spec/impermium/content/connection_spec.rb +257 -0
  158. data/spec/impermium/content/listing_spec.rb +169 -0
  159. data/spec/impermium/user/account_spec.rb +184 -0
  160. data/spec/impermium/user/profile_spec.rb +154 -0
  161. data/spec/spec_helper.rb +32 -0
  162. metadata +433 -0
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour -f d
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm --create ruby-1.9.3-p0@whi
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in impermium.gemspec
4
+ gemspec
data/MIT-LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 WHI Inc, Juanjo Bazán, Bosko Ivanisevic and Neil Berkman
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # Impermium #
2
+
3
+ Ruby wrapper for the [Impermium API](http://impermium.com).
4
+
5
+ * gem version 1.0.0 supports the Impermium API version 3.1
6
+
7
+ ## Usage ##
8
+
9
+ In order to use Impermium gem you must get an Impermium API key.
10
+
11
+ ### Instantiate and configure a client ###
12
+
13
+ The Impermium client can be instantiated and configured in several ways. A new client can be created with
14
+
15
+ client = Impermium.new(:api_key => <your_api_key>)
16
+
17
+ which is actually short way of
18
+
19
+ client = Impermium::Client.new(:api_key => <your_api_key>)
20
+
21
+ Constructor accepts a hash of options that can be used to configure the Impermium client. Valid hash keys are
22
+
23
+ * `:adapter` (sets Faraday adapter)
24
+ * `:api_version` (sets Impermium API version - default 3.1)
25
+ * `:api_key` (sets API key)
26
+ * `:client_name` (sets client name)
27
+ * `:client_id` (sets client ID)
28
+ * `:endpoint` (sets URL to Impermium server - default http://api.impermium.com)
29
+
30
+ Either of these values can be set directly too:
31
+
32
+ * client = Impermium.new
33
+ * client.api_key = <your_api_key>
34
+ * client.endpoint = "http://api-test.impermium.com"
35
+
36
+ Finally, Impermium client can be configured through a block with:
37
+
38
+ Impermium.configure do |conf|
39
+ conf.api_key = <your_api_key>
40
+ conf.endpoint = "http://api-test.impermium.com"
41
+ end
42
+
43
+ client = Impermium.new
44
+
45
+ ### Calling API methods ###
46
+
47
+ Each method accepts the mandatory arguments of the correspondent API call, and have an options hash and a block as optional arguments. Here is the list of all supported methods and their mandatory arguments:
48
+
49
+ * __USER__
50
+ + __Account:__
51
+ - `client.account(user_id, enduser_ip)`
52
+ - `client.account_attempt(enduser_ip)`
53
+ - `client.account_login(user_id, enduser_ip)`
54
+ - `client.account_analyst_feedback(analyst_id, user_id, desired_result)`
55
+ - `client.account_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, user_id, desired_result)`
56
+
57
+ + __Profile:__
58
+ - `client.profile(user_id, profile_id, enduser_ip)`
59
+ - `client.profile_analyst_feedback(profile_id, analyst_id, desired_result)`
60
+ - `client.profile_user_feedback(profile_id, rep_usr_id, rep_usr_type, reporter_ip, desired_result)`
61
+
62
+ * __CONTENT__
63
+ + __Blog post:__
64
+ - `client.blog_post(user_id, blog_post_id, content, blog_post_permalink, blog_url, enduser_ip)`
65
+ - `client.blog_post_analyst_feedback(analyst_id, blog_post_id, desired_result)`
66
+ - `client.blog_post_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, blog_post_id, desired_result)`
67
+
68
+ + __Bookmark:__
69
+ - `client.bookmark(user_id, bookmark_id, bookmark_url, enduser_ip)`
70
+ - `client.bookmark_like(user_id, bookmark_id, bookmark_url, like_value, enduser_ip)`
71
+ - `client.bookmark_analyst_feedback(analyst_id, bookmark_id, desired_result)`
72
+ - `client.bookmark_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, bookmark_id, desired_result)`
73
+
74
+ + __Comment:__
75
+ - `client.comment(user_id, comment_id, content, comment_permalink, article_permalink, enduser_ip)`
76
+ - `client.comment_analyst_feedback(analyst_id, comment_id, desired_result)`
77
+ - `client.comment_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, comment_id, desired_result)`
78
+
79
+ + __Connection:__
80
+ - `client.connection(operation, connection_type, connection_id, requester_user_id, responder_user_id, enduser_ip)`
81
+ - `client.connection_analyst_feedback(analyst_id, connection_type, connection_id, desired_result)`
82
+ - `client.connection_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, connection_type, connection_id, desired_result)`
83
+
84
+ + __Listing:__
85
+ - `client.listing(user_id, listing_id, content, listing_permalink, enduser_ip)`
86
+ - `client.listing_analyst_feedback(analyst_id, listing_id, desired_result)`
87
+ - `client.listing_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, listing_id, desired_result)`
88
+
89
+ Additional arguments can be passed through the hash which is the last argument for every method
90
+
91
+ client.account('33', '255.255.255.255', {:alias => "user33", :password_hash=>'7d222a5d269a'})
92
+
93
+ If request headers have to be set it can be done through block
94
+
95
+ Impermium.account('33', '255.255.255.255') do |req|
96
+ req.headers = {:http_user_agent => "Impermium gem 1.0.0"}
97
+ end
98
+
99
+ You can find the complete arguments lists and types in the official Impermium API docs site.
100
+
101
+ ### Responses ###
102
+
103
+ Any method call receiving a successful response from impermium API will return a Hash like structure containing the body of the response, typically including `response_id`, `timestamp` and posibly `spam_classifier` and any other additional classifiers.
104
+
105
+ Any 4XX response will raise an Impermium Exception with the body of the response in the error message.
106
+
107
+ * A 400 status response from the impermium API will raise an `Impermium::BadRequest`
108
+ * A 401 status response from the impermium API will raise an `Impermium::UnauthorizedRequest`
109
+ * A 403 status response from the impermium API will raise an `Impermium::ForbiddenRequest`
110
+ * A 404 status response from the impermium API will raise an `Impermium::NotFoundRequest`
111
+
112
+ ## Credits ##
113
+
114
+ Here is the [list of contributors](https://github.com/weheartit/impermium/contributors)\.
115
+
116
+ ## License ##
117
+
118
+ Copyright 2012 WHI Inc. \([weheartit.com](http://weheartit.com)\), released under the MIT license.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+
4
+ Bundler::GemHelper.install_tasks
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+ task :default => :spec
data/impermium.gemspec ADDED
@@ -0,0 +1,31 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "impermium/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "impermium"
7
+ s.version = Impermium::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.date = Time.now.strftime('%Y-%m-%d')
10
+
11
+ s.authors = ["Juanjo Bazán", "Bosko Ivanisevic", "Neil Berkman"]
12
+ s.email = ["jjbazan@gmail.com"]
13
+ s.homepage = "https://github.com/weheartit/impermium"
14
+ s.summary = "Impermium API wrapper"
15
+ s.description = "Ruby wrapper for the Impermium social spam API"
16
+
17
+ s.add_dependency "faraday", "~> 0.7.4"
18
+ s.add_dependency "faraday_middleware", "~> 0.7.0"
19
+ s.add_dependency "hashie", "~> 1.1.0"
20
+ s.add_dependency "yajl-ruby", "~> 0.8.3"
21
+ s.add_dependency "multi_json"
22
+
23
+ s.add_development_dependency "rspec", "~> 2.8.0"
24
+ s.add_development_dependency "webmock", "~> 1.8.1"
25
+ s.add_development_dependency "vcr", "~> 2.0.0"
26
+
27
+ s.files = `git ls-files`.split("\n")
28
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
29
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
30
+ s.require_paths = ["lib"]
31
+ end
@@ -0,0 +1,18 @@
1
+ require 'faraday'
2
+
3
+ module Faraday
4
+ class Response::Raise4xx < Response::Middleware
5
+ def on_complete(env)
6
+ case env[:status].to_i
7
+ when 400
8
+ raise Impermium::BadRequest.new(env[:method].to_s.upcase, env[:url].to_s, env[:body])
9
+ when 401
10
+ raise Impermium::UnauthorizedRequest.new(env[:method].to_s.upcase, env[:url].to_s, env[:body])
11
+ when 403
12
+ raise Impermium::ForbiddenRequest.new(env[:method].to_s.upcase, env[:url].to_s, env[:body])
13
+ when 404
14
+ raise Impermium::NotFoundRequest.new(env[:method].to_s.upcase, env[:url].to_s, env[:body])
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,57 @@
1
+ require "uri"
2
+ require "faraday"
3
+ require "faraday_middleware"
4
+ require "impermium/configuration"
5
+ require "impermium/content"
6
+ require "impermium/errors"
7
+ require "impermium/user"
8
+ require "faraday/raise_4xx"
9
+
10
+ module Impermium
11
+ class Client
12
+ include Configuration
13
+ include Content
14
+ include User
15
+
16
+ def initialize(options = {})
17
+ options = Impermium.options.merge(options)
18
+ Configuration::VALID_CONFIG_KEYS.each do |key|
19
+ send("#{key}=", options[key])
20
+ end
21
+ end
22
+
23
+ def api_connection
24
+ @api_connection ||= Faraday.new(:url => endpoint, :headers => default_headers) do |builder|
25
+ builder.use Faraday::Response::Mashify
26
+ builder.use Faraday::Response::ParseJson
27
+ builder.use Faraday::Response::Raise4xx
28
+ builder.request :json
29
+
30
+ builder.adapter adapter
31
+ end
32
+ end
33
+
34
+ def post(url, options={})
35
+ api_connection.post do |req|
36
+ req.url api_url(url)
37
+ req.body = options
38
+ req.headers['Content-Type'] = 'application/json'
39
+ yield req if block_given?
40
+ end.body
41
+ end
42
+
43
+ def api_url(request_path)
44
+ url = URI.join(endpoint,
45
+ request_path[-1] == '/' ? request_path : request_path + "/",
46
+ api_version + "/",
47
+ api_key + "/").to_s
48
+ end
49
+
50
+ private
51
+
52
+ def default_headers
53
+ { :http_user_agent => "Impermium Ruby Gem",
54
+ :http_accept => "application/json"}
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,44 @@
1
+ module Impermium
2
+ module Configuration
3
+ VALID_CONFIG_KEYS = [
4
+ :adapter,
5
+ :api_version,
6
+ :api_key,
7
+ :client_name,
8
+ :client_id,
9
+ :endpoint
10
+ ].freeze
11
+
12
+ DEFAULT_ADAPTER = :net_http
13
+ DEFAULT_API_VERSION = "3.1"
14
+ DEFAULT_API_KEY = nil
15
+ DEFAULT_CLIENT_NAME = nil
16
+ DEFAULT_CLIENT_ID = nil
17
+ DEFAULT_ENDPOINT = "http://api.impermium.com"
18
+
19
+ attr_accessor *VALID_CONFIG_KEYS
20
+
21
+ def self.extended(base)
22
+ base.reset
23
+ end
24
+
25
+ def configure
26
+ yield self
27
+ end
28
+
29
+ def options
30
+ options = {}
31
+ VALID_CONFIG_KEYS.each { |key| options[key] = send(key) }
32
+ options
33
+ end
34
+
35
+ def reset
36
+ self.adapter = DEFAULT_ADAPTER
37
+ self.api_version = DEFAULT_API_VERSION
38
+ self.api_key = DEFAULT_API_KEY
39
+ self.client_name = DEFAULT_CLIENT_NAME
40
+ self.client_id = DEFAULT_CLIENT_ID
41
+ self.endpoint = DEFAULT_ENDPOINT
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,38 @@
1
+ module Impermium
2
+ module BlogPost
3
+ REPORTER_USER_TYPE_VALUES = ["ENDUSER", "MODERATOR"] # => default first
4
+
5
+ def blog_post(user_id, blog_post_id, content, blog_post_permalink, blog_url, enduser_ip, options={}, &block)
6
+ options.merge!(
7
+ :user_id => user_id,
8
+ :blog_post_id => blog_post_id,
9
+ :content => content,
10
+ :blog_post_permalink => blog_post_permalink,
11
+ :blog_url => blog_url,
12
+ :enduser_ip => enduser_ip
13
+ )
14
+ post("blog_post", options, &block)
15
+ end
16
+
17
+ def blog_post_analyst_feedback(analyst_id, blog_post_id, desired_result, options={}, &block)
18
+ options.merge!(
19
+ :analyst_id => analyst_id,
20
+ :blog_post_id => blog_post_id,
21
+ :desired_result => desired_result
22
+ )
23
+ post("blog_post/analyst_feedback", options, &block)
24
+ end
25
+
26
+ def blog_post_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, blog_post_id, desired_result, options={}, &block)
27
+ options.merge!(
28
+ :reporter_user_id => rep_usr_id,
29
+ :reporter_user_type => REPORTER_USER_TYPE_VALUES.include?(rep_usr_type) ? rep_usr_type : REPORTER_USER_TYPE_VALUES.first,
30
+ :reporter_ip => reporter_ip,
31
+ :blog_post_id => blog_post_id,
32
+ :desired_result => desired_result
33
+ )
34
+ post("blog_post/user_feedback", options, &block)
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,47 @@
1
+ module Impermium
2
+ module Bookmark
3
+ REPORTER_USER_TYPE_VALUES = ["ENDUSER", "MODERATOR"] # => default first
4
+
5
+ def bookmark(user_id, bookmark_id, bookmark_url, enduser_ip, options={}, &block)
6
+ options.merge!(
7
+ :user_id => user_id,
8
+ :bookmark_id => bookmark_id,
9
+ :bookmark_url => bookmark_url,
10
+ :enduser_ip => enduser_ip
11
+ )
12
+ post("bookmark", options, &block)
13
+ end
14
+
15
+ def bookmark_like(user_id, bookmark_id, bookmark_url, like_value, enduser_ip, options={}, &block)
16
+ options.merge!(
17
+ :user_id => user_id,
18
+ :bookmark_id => bookmark_id,
19
+ :bookmark_url => bookmark_url,
20
+ :like_value => like_value,
21
+ :enduser_ip => enduser_ip
22
+ )
23
+ post("bookmark/like", options, &block)
24
+ end
25
+
26
+ def bookmark_analyst_feedback(analyst_id, bookmark_id, desired_result, options={}, &block)
27
+ options.merge!(
28
+ :analyst_id => analyst_id,
29
+ :bookmark_id => bookmark_id,
30
+ :desired_result => desired_result
31
+ )
32
+ post("bookmark/analyst_feedback", options, &block)
33
+ end
34
+
35
+ def bookmark_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, bookmark_id, desired_result, options={}, &block)
36
+ options.merge!(
37
+ :reporter_user_id => rep_usr_id,
38
+ :reporter_user_type => REPORTER_USER_TYPE_VALUES.include?(rep_usr_type) ? rep_usr_type : REPORTER_USER_TYPE_VALUES.first,
39
+ :reporter_ip => reporter_ip,
40
+ :bookmark_id => bookmark_id,
41
+ :desired_result => desired_result
42
+ )
43
+ post("bookmark/user_feedback", options, &block)
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,38 @@
1
+ module Impermium
2
+ module Comment
3
+ REPORTER_USER_TYPE_VALUES = ["ENDUSER", "MODERATOR"] # => default first
4
+
5
+ def comment(user_id, comment_id, content, comment_permalink, article_permalink, enduser_ip, options={}, &block)
6
+ options.merge!(
7
+ :user_id => user_id,
8
+ :comment_id => comment_id,
9
+ :content => content,
10
+ :comment_permalink => comment_permalink,
11
+ :article_permalink => article_permalink,
12
+ :enduser_ip => enduser_ip
13
+ )
14
+ post("comment", options, &block)
15
+ end
16
+
17
+ def comment_analyst_feedback(analyst_id, comment_id, desired_result, options={}, &block)
18
+ options.merge!(
19
+ :analyst_id => analyst_id,
20
+ :comment_id => comment_id,
21
+ :desired_result => desired_result
22
+ )
23
+ post("comment/analyst_feedback", options, &block)
24
+ end
25
+
26
+ def comment_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, comment_id, desired_result, options={}, &block)
27
+ options.merge!(
28
+ :reporter_user_id => rep_usr_id,
29
+ :reporter_user_type => REPORTER_USER_TYPE_VALUES.include?(rep_usr_type) ? rep_usr_type : REPORTER_USER_TYPE_VALUES.first,
30
+ :reporter_ip => reporter_ip,
31
+ :comment_id => comment_id,
32
+ :desired_result => desired_result
33
+ )
34
+ post("comment/user_feedback", options, &block)
35
+ end
36
+
37
+ end
38
+ end
@@ -0,0 +1,42 @@
1
+ module Impermium
2
+ module Connection
3
+ REPORTER_USER_TYPE_VALUES = ["ENDUSER", "MODERATOR"] # => default first
4
+ OPERATION_VALUES = ['request', 'response'] # => default first
5
+ CONNECTION_TYPE_VALUES = ['follow', 'friend']
6
+
7
+ def connection(operation, connection_type, connection_id, requester_user_id, responder_user_id, enduser_ip, options={}, &block)
8
+ options.merge!(
9
+ :operation => OPERATION_VALUES.include?(operation) ? operation : OPERATION_VALUES.first,
10
+ :connection_type => connection_type,
11
+ :connection_id => connection_id,
12
+ :requester_user_id => requester_user_id,
13
+ :responder_user_id => responder_user_id,
14
+ :enduser_ip => enduser_ip
15
+ )
16
+ post("connection", options, &block)
17
+ end
18
+
19
+ def connection_analyst_feedback(analyst_id, connection_type, connection_id, desired_result, options={}, &block)
20
+ options.merge!(
21
+ :analyst_id => analyst_id,
22
+ :connection_type => connection_type,
23
+ :connection_id => connection_id,
24
+ :desired_result => desired_result
25
+ )
26
+ post("connection/analyst_feedback", options, &block)
27
+ end
28
+
29
+ def connection_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, connection_type, connection_id, desired_result, options={}, &block)
30
+ options.merge!(
31
+ :reporter_user_id => rep_usr_id,
32
+ :reporter_user_type => REPORTER_USER_TYPE_VALUES.include?(rep_usr_type) ? rep_usr_type : REPORTER_USER_TYPE_VALUES.first,
33
+ :reporter_ip => reporter_ip,
34
+ :connection_type => connection_type,
35
+ :connection_id => connection_id,
36
+ :desired_result => desired_result
37
+ )
38
+ post("connection/user_feedback", options, &block)
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,37 @@
1
+ module Impermium
2
+ module Listing
3
+ REPORTER_USER_TYPE_VALUES = ["ENDUSER", "MODERATOR"] # => default first
4
+
5
+ def listing(user_id, listing_id, content, listing_permalink, enduser_ip, options={}, &block)
6
+ options.merge!(
7
+ :user_id => user_id,
8
+ :listing_id => listing_id,
9
+ :content => content,
10
+ :listing_permalink => listing_permalink,
11
+ :enduser_ip => enduser_ip
12
+ )
13
+ post("listing", options, &block)
14
+ end
15
+
16
+ def listing_analyst_feedback(analyst_id, listing_id, desired_result, options={}, &block)
17
+ options.merge!(
18
+ :analyst_id => analyst_id,
19
+ :listing_id => listing_id,
20
+ :desired_result => desired_result
21
+ )
22
+ post("listing/analyst_feedback", options, &block)
23
+ end
24
+
25
+ def listing_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, listing_id, desired_result, options={}, &block)
26
+ options.merge!(
27
+ :reporter_user_id => rep_usr_id,
28
+ :reporter_user_type => REPORTER_USER_TYPE_VALUES.include?(rep_usr_type) ? rep_usr_type : REPORTER_USER_TYPE_VALUES.first,
29
+ :reporter_ip => reporter_ip,
30
+ :listing_id => listing_id,
31
+ :desired_result => desired_result
32
+ )
33
+ post("listing/user_feedback", options, &block)
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,15 @@
1
+ require "impermium/content/blog_post"
2
+ require "impermium/content/bookmark"
3
+ require "impermium/content/comment"
4
+ require "impermium/content/connection"
5
+ require "impermium/content/listing"
6
+
7
+ module Impermium
8
+ module Content
9
+ include BlogPost
10
+ include Bookmark
11
+ include Comment
12
+ include Connection
13
+ include Listing
14
+ end
15
+ end
@@ -0,0 +1,25 @@
1
+ module Impermium
2
+ class BaseError < StandardError
3
+ attr_reader :request_type
4
+ attr_reader :request_url
5
+
6
+ def initialize(request_type, request_url, message)
7
+ @request_type = request_type
8
+ @request_url = request_url
9
+ super message
10
+ end
11
+ end
12
+
13
+ class BadRequest < BaseError
14
+ end
15
+
16
+ class UnauthorizedReqeust < BaseError
17
+ end
18
+
19
+ class ForbiddenRequest < BaseError
20
+ end
21
+
22
+ class NotFoundRequest < BaseError
23
+ end
24
+
25
+ end
@@ -0,0 +1,50 @@
1
+ module Impermium
2
+ module Account
3
+ REPORTER_USER_TYPE_VALUES = ["ENDUSER", "MODERATOR"] # => default first
4
+
5
+ def account(user_id, enduser_ip, options={}, &block)
6
+ options.merge!(
7
+ :user_id => user_id,
8
+ :enduser_ip => enduser_ip
9
+ )
10
+ post("account", options, &block)
11
+ end
12
+
13
+ def account_attempt(enduser_ip, options={}, &block)
14
+ options.merge!(
15
+ :enduser_ip => enduser_ip
16
+ )
17
+ post("account/attempt", options, &block)
18
+ end
19
+
20
+ def account_login(user_id, enduser_ip, options={}, &block)
21
+ options.merge!(
22
+ :user_id => user_id,
23
+ :enduser_ip => enduser_ip
24
+ )
25
+ post("account/login", options, &block)
26
+ end
27
+
28
+ def account_analyst_feedback(analyst_id, user_id, desired_result, options={}, &block)
29
+ options.merge!(
30
+ :analyst_id => analyst_id,
31
+ :user_id => user_id,
32
+ :desired_result => desired_result
33
+ )
34
+ post("account/analyst_feedback", options, &block)
35
+ end
36
+
37
+ def account_user_feedback(rep_usr_id, rep_usr_type, reporter_ip, user_id, desired_result, options={}, &block)
38
+ options.merge!(
39
+ :reporter_user_id => rep_usr_id,
40
+ :reporter_user_type => REPORTER_USER_TYPE_VALUES.include?(rep_usr_type) ? rep_usr_type : REPORTER_USER_TYPE_VALUES.first,
41
+ :reporter_ip => reporter_ip,
42
+ :user_id => user_id,
43
+ :desired_result => desired_result
44
+ )
45
+ post("account/user_feedback", options, &block)
46
+ end
47
+
48
+
49
+ end
50
+ end
@@ -0,0 +1,35 @@
1
+ module Impermium
2
+ module Profile
3
+ REPORTER_USER_TYPE_VALUES = ["ENDUSER", "MODERATOR"] # => default first
4
+
5
+ def profile(user_id, profile_id, enduser_ip, options={}, &block)
6
+ options.merge!(
7
+ :user_id => user_id,
8
+ :profile_id => profile_id,
9
+ :enduser_ip => enduser_ip
10
+ )
11
+ post("profile", options, &block)
12
+ end
13
+
14
+ def profile_analyst_feedback(profile_id, analyst_id, desired_result, options={}, &block)
15
+ options.merge!(
16
+ :profile_id => profile_id,
17
+ :analyst_id => analyst_id,
18
+ :desired_result => desired_result
19
+ )
20
+ post("profile/analyst_feedback", options, &block)
21
+ end
22
+
23
+ def profile_user_feedback(profile_id, rep_usr_id, rep_usr_type, reporter_ip, desired_result, options={}, &block)
24
+ options.merge!(
25
+ :profile_id => profile_id,
26
+ :reporter_user_id => rep_usr_id,
27
+ :reporter_user_type => REPORTER_USER_TYPE_VALUES.include?(rep_usr_type) ? rep_usr_type : REPORTER_USER_TYPE_VALUES.first,
28
+ :reporter_ip => reporter_ip,
29
+ :desired_result => desired_result
30
+ )
31
+ post("profile/user_feedback", options, &block)
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ require "impermium/user/account"
2
+ require "impermium/user/profile"
3
+
4
+ module Impermium
5
+ module User
6
+ include Account
7
+ include Profile
8
+ end
9
+ end
@@ -0,0 +1,3 @@
1
+ module Impermium
2
+ VERSION = "1.0.0"
3
+ end