tigre-client 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+
5
+ test.rb
data/.rvmrc ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # This is an RVM Project .rvmrc file, used to automatically load the ruby
4
+ # development environment upon cd'ing into the directory
5
+
6
+ # First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
7
+ environment_id="ruby-1.9.2-p180@tigre-client"
8
+
9
+ #
10
+ # First we attempt to load the desired environment directly from the environment
11
+ # file. This is very fast and efficicent compared to running through the entire
12
+ # CLI and selector. If you want feedback on which environment was used then
13
+ # insert the word 'use' after --create as this triggers verbose mode.
14
+ #
15
+ if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
16
+ && -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
17
+ \. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
18
+ else
19
+ # If the environment file has not yet been created, use the RVM CLI to select.
20
+ rvm --create "$environment_id"
21
+ fi
22
+
23
+ #
24
+ # If you use an RVM gemset file to install a list of gems (*.gems), you can have
25
+ # it be automatically loaded. Uncomment the following and adjust the filename if
26
+ # necessary.
27
+ #
28
+ # filename=".gems"
29
+ # if [[ -s "$filename" ]] ; then
30
+ # rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
31
+ # fi
32
+
33
+ #
34
+ # If you use bundler and would like to run bundle each time you enter the
35
+ # directory, you can uncomment the following code.
36
+ #
37
+ # # Ensure that Bundler is installed. Install it if it is not.
38
+ # if ! command -v bundle >/dev/null; then
39
+ # printf "The rubygem 'bundler' is not installed. Installing it now.\n"
40
+ # gem install bundler
41
+ # fi
42
+ #
43
+ # # Bundle while reducing excess noise.
44
+ # printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
45
+ # bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
46
+ #
47
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in tigre-client.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ tigre-client (0.0.5)
5
+ curb (~> 0.7.12)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ curb (0.7.14)
11
+ diff-lcs (1.1.2)
12
+ rspec (2.5.0)
13
+ rspec-core (~> 2.5.0)
14
+ rspec-expectations (~> 2.5.0)
15
+ rspec-mocks (~> 2.5.0)
16
+ rspec-core (2.5.1)
17
+ rspec-expectations (2.5.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.5.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ rspec
26
+ tigre-client!
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,30 @@
1
+ module Tigre
2
+ class Sample
3
+
4
+ # mimics a curl POST request using Curl
5
+ # required params
6
+
7
+ # optional params
8
+
9
+ def self.post(file_location, md5, options={})
10
+
11
+ if file_location == ''|| md5 == ''
12
+ raise ArguementError, "File_location or md5 parameter cannot be empty"
13
+ end
14
+
15
+ c = Curl::Easy.new("#{Tigre.endpoint}/samples")
16
+ c.multipart_form_post = true
17
+ c.headers["API_TOKEN"] = Tigre.token
18
+
19
+ post_data = options.map { |k, v| Curl::PostField.content(k, v.to_s) }
20
+
21
+ post_data << Curl::PostField.file("file", file_location)
22
+ post_data << Curl::PostField.content("md5", md5)
23
+
24
+ c.http_post(*post_data)
25
+
26
+ return [c.response_code, c.body_str]
27
+ end
28
+
29
+ end
30
+ end
@@ -0,0 +1,106 @@
1
+ module Tigre
2
+ class Url
3
+
4
+ # mimics a curl POST request using Curl
5
+ # required params
6
+ # url - String
7
+ # options - Hash
8
+ # :source_name - String
9
+ # optional params
10
+ # options - Hash
11
+ # :shareable - Boolean, :default => false
12
+ def self.post(url, options={})
13
+
14
+ if url == ''
15
+ raise ArguementError, "Missing url parameter"
16
+ end
17
+
18
+ unless options[:source_name]
19
+ raise ArguementError, "Missing source_name parameter"
20
+ end
21
+
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
+ }
28
+ post_data = fields_hash.map { |k, v| Curl::PostField.content(k, v.to_s) }
29
+
30
+ puts post_data
31
+ puts post_data.inspect
32
+
33
+ c = Curl::Easy.new("#{Tigre.endpoint}/urls")
34
+ c.multipart_form_post = false
35
+ c.headers["API_TOKEN"] = Tigre.token
36
+
37
+ c.http_post(post_data)
38
+
39
+ return [c.response_code, c.body_str]
40
+ end
41
+
42
+ # mimics a curl GET request using Curl
43
+ # required params
44
+ # sha256 - String
45
+ def self.get(sha256)
46
+ if sha256.nil? || sha256 == ''
47
+ raise ArguementError, "Missing sha256 parameter"
48
+ end
49
+
50
+ c = Curl::Easy.new("#{Tigre.endpoint}/urls/#{sha256}")
51
+ c.headers["API_TOKEN"] = Tigre.token
52
+ c.perform
53
+ return [c.response_code, c.body_str]
54
+ end
55
+
56
+ # mimics a curl GET request using Curl
57
+ # required params
58
+ # options - Hash
59
+ # :after => Ruby DateTime object OR Integer (epoch time)
60
+ # :before => Ruby DateTime object OR Integer (epoch time)
61
+ def self.daterange(options={})
62
+ if options.nil? || (options[:after].nil? && options[:before].nil?)
63
+ raise ArguementError, "Missing proper parameters (:start_date or :end_date required)"
64
+ end
65
+
66
+ if options[:after] && options[:after].is_a?(Time)
67
+ options[:after] = options[:after].to_i
68
+ end
69
+ if options[:before] && options[:before].is_a?(Time)
70
+ options[:before] = options[:before].to_i
71
+ end
72
+
73
+ c = Curl::Easy.new("#{Tigre.endpoint}/urls/daterange?after=#{options[:after]}&before=#{options[:before]}")
74
+ c.headers["API_TOKEN"] = Tigre.token
75
+ c.perform
76
+ return [c.response_code, c.body_str]
77
+ end
78
+
79
+ # mimics a curl GET request using Curl
80
+ # required params
81
+ # domain - String
82
+ # optional params
83
+ # options - Hash
84
+ # :after => Ruby DateTime object OR Integer (epoch time)
85
+ # :before => Ruby DateTime object OR Integer (epoch time)
86
+ def self.domains(domain, options={})
87
+ if domain.nil? || domain == ''
88
+ raise ArguementError, "Missing domain parameter"
89
+ end
90
+
91
+ if options[:after] && options[:after].is_a?(Time)
92
+ options[:after] = options[:after].to_i
93
+ end
94
+ if options[:before] && options[:before].is_a?(Time)
95
+ options[:before] = options[:before].to_i
96
+ end
97
+
98
+ c = Curl::Easy.new("#{Tigre.endpoint}/urls/domains?domain=#{domain}&after=#{options[:after]}&before=#{options[:before]}")
99
+ c.headers["API_TOKEN"] = Tigre.token
100
+ c.perform
101
+ return [c.response_code, c.body_str]
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -0,0 +1,5 @@
1
+ module Tigre
2
+ module Client
3
+ VERSION = "0.0.6"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require 'tigre-client/url'
2
+ require 'tigre-client/sample'
3
+ require 'curb'
4
+
5
+ module Tigre
6
+
7
+ class << self
8
+ attr_accessor :token, :endpoint
9
+
10
+ def configure
11
+ yield self
12
+ true
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "tigre-client/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "tigre-client"
7
+ s.version = Tigre::Client::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Marcio Castilho", "Brad Cantin"]
10
+ s.email = ["marcioc@sunbelt-software.com", "bradc@sunbelt-software.com"]
11
+ s.homepage = "https://gfisoftware.unfuddle.com/a#/projects/4"
12
+ s.summary = %q{Tigre Client API Library}
13
+ s.description = %q{Tigre Client API Library}
14
+
15
+ s.rubyforge_project = "tigre-client"
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+
22
+ s.required_ruby_version = '>= 1.9.2'
23
+
24
+ s.add_development_dependency "rspec"
25
+
26
+ s.add_dependency('curb', '~> 0.7.12')
27
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tigre-client
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.6
6
+ platform: ruby
7
+ authors:
8
+ - Marcio Castilho
9
+ - Brad Cantin
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+
14
+ date: 2011-03-24 00:00:00 -04:00
15
+ default_executable:
16
+ dependencies:
17
+ - !ruby/object:Gem::Dependency
18
+ name: rspec
19
+ prerelease: false
20
+ requirement: &id001 !ruby/object:Gem::Requirement
21
+ none: false
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: "0"
26
+ type: :development
27
+ version_requirements: *id001
28
+ - !ruby/object:Gem::Dependency
29
+ name: curb
30
+ prerelease: false
31
+ requirement: &id002 !ruby/object:Gem::Requirement
32
+ none: false
33
+ requirements:
34
+ - - ~>
35
+ - !ruby/object:Gem::Version
36
+ version: 0.7.12
37
+ type: :runtime
38
+ version_requirements: *id002
39
+ description: Tigre Client API Library
40
+ email:
41
+ - marcioc@sunbelt-software.com
42
+ - bradc@sunbelt-software.com
43
+ executables: []
44
+
45
+ extensions: []
46
+
47
+ extra_rdoc_files: []
48
+
49
+ files:
50
+ - .gitignore
51
+ - .rvmrc
52
+ - Gemfile
53
+ - Gemfile.lock
54
+ - Rakefile
55
+ - lib/tigre-client.rb
56
+ - lib/tigre-client/sample.rb
57
+ - lib/tigre-client/url.rb
58
+ - lib/tigre-client/version.rb
59
+ - tigre-client.gemspec
60
+ has_rdoc: true
61
+ homepage: https://gfisoftware.unfuddle.com/a#/projects/4
62
+ licenses: []
63
+
64
+ post_install_message:
65
+ rdoc_options: []
66
+
67
+ require_paths:
68
+ - lib
69
+ required_ruby_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 1.9.2
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: "0"
81
+ requirements: []
82
+
83
+ rubyforge_project: tigre-client
84
+ rubygems_version: 1.6.2
85
+ signing_key:
86
+ specification_version: 3
87
+ summary: Tigre Client API Library
88
+ test_files: []
89
+