tigre-client 0.0.6 → 0.0.7

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.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tigre-client (0.0.5)
4
+ tigre-client (0.0.7)
5
5
  curb (~> 0.7.12)
6
6
 
7
7
  GEM
@@ -2,12 +2,13 @@ module Tigre
2
2
  class Sample
3
3
 
4
4
  # mimics a curl POST request using Curl
5
- # required params
6
-
5
+ # required params
6
+ # file_location - String path to the file
7
+ # md5 - String
7
8
  # optional params
8
-
9
+ # options - Hash (reserved for future use)
9
10
  def self.post(file_location, md5, options={})
10
-
11
+
11
12
  if file_location == ''|| md5 == ''
12
13
  raise ArguementError, "File_location or md5 parameter cannot be empty"
13
14
  end
@@ -15,16 +16,16 @@ module Tigre
15
16
  c = Curl::Easy.new("#{Tigre.endpoint}/samples")
16
17
  c.multipart_form_post = true
17
18
  c.headers["API_TOKEN"] = Tigre.token
18
-
19
+
19
20
  post_data = options.map { |k, v| Curl::PostField.content(k, v.to_s) }
20
21
 
21
22
  post_data << Curl::PostField.file("file", file_location)
22
23
  post_data << Curl::PostField.content("md5", md5)
23
24
 
24
25
  c.http_post(*post_data)
25
-
26
+
26
27
  return [c.response_code, c.body_str]
27
28
  end
28
-
29
+
29
30
  end
30
- end
31
+ end
@@ -1,8 +1,8 @@
1
1
  module Tigre
2
2
  class Url
3
-
3
+
4
4
  # mimics a curl POST request using Curl
5
- # required params
5
+ # required params
6
6
  # url - String
7
7
  # options - Hash
8
8
  # :source_name - String
@@ -10,35 +10,35 @@ module Tigre
10
10
  # options - Hash
11
11
  # :shareable - Boolean, :default => false
12
12
  def self.post(url, options={})
13
-
13
+
14
14
  if url == ''
15
15
  raise ArguementError, "Missing url parameter"
16
16
  end
17
-
17
+
18
18
  unless options[:source_name]
19
19
  raise ArguementError, "Missing source_name parameter"
20
20
  end
21
-
21
+
22
22
  # prepare post data
23
- fields_hash = {
24
- "url[original_url]" => url,
25
- "url[source_name]" => options[:source_name],
26
- "url[shareable]" => options[:shareable]
27
- }
23
+ fields_hash = {
24
+ "url[original_url]" => url,
25
+ "url[source_name]" => options[:source_name],
26
+ "url[shareable]" => options[:shareable]
27
+ }
28
28
  post_data = fields_hash.map { |k, v| Curl::PostField.content(k, v.to_s) }
29
-
29
+
30
30
  puts post_data
31
31
  puts post_data.inspect
32
32
 
33
33
  c = Curl::Easy.new("#{Tigre.endpoint}/urls")
34
34
  c.multipart_form_post = false
35
35
  c.headers["API_TOKEN"] = Tigre.token
36
-
36
+
37
37
  c.http_post(post_data)
38
-
38
+
39
39
  return [c.response_code, c.body_str]
40
40
  end
41
-
41
+
42
42
  # mimics a curl GET request using Curl
43
43
  # required params
44
44
  # sha256 - String
@@ -46,13 +46,23 @@ module Tigre
46
46
  if sha256.nil? || sha256 == ''
47
47
  raise ArguementError, "Missing sha256 parameter"
48
48
  end
49
-
49
+
50
50
  c = Curl::Easy.new("#{Tigre.endpoint}/urls/#{sha256}")
51
51
  c.headers["API_TOKEN"] = Tigre.token
52
52
  c.perform
53
53
  return [c.response_code, c.body_str]
54
54
  end
55
55
 
56
+ def self.index(options={})
57
+ options[:page] ||= 0
58
+ options[:per] ||= 50
59
+
60
+ c = Curl::Easy.new("#{Tigre.endpoint}/urls?page=#{options[:page]}&per=#{options[:per]}")
61
+ c.headers["API_TOKEN"] = Tigre.token
62
+ c.perform
63
+ return [c.response_code, c.body_str]
64
+ end
65
+
56
66
  # mimics a curl GET request using Curl
57
67
  # required params
58
68
  # options - Hash
@@ -62,7 +72,7 @@ module Tigre
62
72
  if options.nil? || (options[:after].nil? && options[:before].nil?)
63
73
  raise ArguementError, "Missing proper parameters (:start_date or :end_date required)"
64
74
  end
65
-
75
+
66
76
  if options[:after] && options[:after].is_a?(Time)
67
77
  options[:after] = options[:after].to_i
68
78
  end
@@ -70,12 +80,15 @@ module Tigre
70
80
  options[:before] = options[:before].to_i
71
81
  end
72
82
 
73
- c = Curl::Easy.new("#{Tigre.endpoint}/urls/daterange?after=#{options[:after]}&before=#{options[:before]}")
83
+ options[:page] ||= 0
84
+ options[:per] ||= 50
85
+
86
+ c = Curl::Easy.new("#{Tigre.endpoint}/urls/daterange?after=#{options[:after]}&before=#{options[:before]}&page=#{options[:page]}&per=#{options[:per]}")
74
87
  c.headers["API_TOKEN"] = Tigre.token
75
88
  c.perform
76
89
  return [c.response_code, c.body_str]
77
90
  end
78
-
91
+
79
92
  # mimics a curl GET request using Curl
80
93
  # required params
81
94
  # domain - String
@@ -87,7 +100,7 @@ module Tigre
87
100
  if domain.nil? || domain == ''
88
101
  raise ArguementError, "Missing domain parameter"
89
102
  end
90
-
103
+
91
104
  if options[:after] && options[:after].is_a?(Time)
92
105
  options[:after] = options[:after].to_i
93
106
  end
@@ -95,12 +108,15 @@ module Tigre
95
108
  options[:before] = options[:before].to_i
96
109
  end
97
110
 
98
- c = Curl::Easy.new("#{Tigre.endpoint}/urls/domains?domain=#{domain}&after=#{options[:after]}&before=#{options[:before]}")
111
+ options[:page] ||= 0
112
+ options[:per] ||= 50
113
+
114
+ c = Curl::Easy.new("#{Tigre.endpoint}/urls/domains?domain=#{domain}&after=#{options[:after]}&before=#{options[:before]}&page=#{options[:page]}&per=#{options[:per]}")
99
115
  c.headers["API_TOKEN"] = Tigre.token
100
116
  c.perform
101
117
  return [c.response_code, c.body_str]
102
118
  end
103
-
119
+
104
120
  end
105
-
106
- end
121
+
122
+ end
@@ -1,5 +1,5 @@
1
1
  module Tigre
2
2
  module Client
3
- VERSION = "0.0.6"
3
+ VERSION = "0.0.7"
4
4
  end
5
5
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: tigre-client
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.6
5
+ version: 0.0.7
6
6
  platform: ruby
7
7
  authors:
8
8
  - Marcio Castilho
@@ -11,7 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-03-24 00:00:00 -04:00
14
+ date: 2011-03-28 00:00:00 -04:00
15
15
  default_executable:
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency