grabbio 0.0.3

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/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in grabbio.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/grabbio.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "grabbio/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "grabbio"
7
+ s.version = Grabbio::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Gazler"]
10
+ s.email = ["gary@banta.tv"]
11
+ s.homepage = "http://github.com/Gazler/"
12
+ s.summary = "A ruby wrapper for the grabbio platform"
13
+ s.description = "A ruby wrapper for the grabbio platform"
14
+
15
+ s.rubyforge_project = "grabbio"
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
+ end
22
+
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'json'
5
+
6
+ module Grabbio
7
+ API_URL = "http://grabb.io/api/"
8
+ API_VERSION = "v1"
9
+
10
+
11
+ def self.new(api_key, api_secret)
12
+ Grabbio::Client.new(api_key, api_secret)
13
+ end
14
+
15
+ class Client
16
+
17
+ include Grabbio::Utils
18
+
19
+ def initialize(api_key, api_secret)
20
+ @api_key = api_key
21
+ @api_secret = api_secret
22
+ end
23
+
24
+ def grab(source, upload_url, opts = {})
25
+ raise ArgumentError.new("Source URL must be a URL") unless source.is_a? String
26
+ raise ArgumentError.new("Upload URL must be a URL") unless upload_url.is_a? String
27
+ opts[:token] = @api_key
28
+ opts[:source] = source
29
+ opts[:upload_url] = upload_url
30
+ opts[:server_time] = Time.now.to_i
31
+ parameters = parameters_to_string(opts)
32
+ hash = sign_request(@api_secret, parameters[1..-1])
33
+ parameters += "&hash=#{hash}"
34
+ url = API_URL+API_VERSION+"/videos.json#{parameters}"
35
+ p url
36
+ make_request(url)
37
+ end
38
+
39
+ end
40
+ end
41
+
42
+
43
+ class GrabbioError < StandardError
44
+ end
45
+
@@ -0,0 +1,50 @@
1
+ require 'base64'
2
+ require 'openssl'
3
+
4
+ module Grabbio
5
+ module Utils
6
+
7
+ def parameters_to_string(parameters)
8
+ first = true
9
+ args = ""
10
+ parameters.each do |k,v|
11
+ if first
12
+ first = false
13
+ args += "?"
14
+ else
15
+ args += "&"
16
+ end
17
+ args += "#{k}=#{v}"
18
+ end
19
+ args
20
+ end
21
+
22
+ def sign_request(secret_key, parameters)
23
+ p parameters
24
+ Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new('sha1'), secret_key,parameters)).chomp.gsub(/\n/,'')
25
+ end
26
+
27
+ def make_request(request)
28
+ url = URI.parse(URI.escape(request))
29
+ body = Net::HTTP.get_response(url).body
30
+ begin
31
+ result = JSON.parse(body)
32
+ rescue
33
+ result = {'error' => 'JSON Parse Error (grabb.io got it wrong)'}
34
+ end
35
+
36
+ if !result["error"].nil?
37
+ raise GrabbioError.new(result["error"])
38
+ elsif !result["errors"].nil?
39
+ result["errors"].each do |k,v|
40
+ raise GrabbioError.new("#{k} #{v}")
41
+ end
42
+ else
43
+ result
44
+ end
45
+
46
+
47
+ end
48
+ end
49
+ end
50
+
@@ -0,0 +1,4 @@
1
+ module Grabbio
2
+ VERSION = "0.0.3"
3
+ end
4
+
data/lib/grabbio.rb ADDED
@@ -0,0 +1,4 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require 'grabbio/utils'
3
+ require 'grabbio/client'
4
+
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grabbio
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 3
9
+ version: 0.0.3
10
+ platform: ruby
11
+ authors:
12
+ - Gazler
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-04-08 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A ruby wrapper for the grabbio platform
22
+ email:
23
+ - gary@banta.tv
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - .gitignore
32
+ - Gemfile
33
+ - Rakefile
34
+ - grabbio.gemspec
35
+ - lib/grabbio.rb
36
+ - lib/grabbio/client.rb
37
+ - lib/grabbio/utils.rb
38
+ - lib/grabbio/version.rb
39
+ has_rdoc: true
40
+ homepage: http://github.com/Gazler/
41
+ licenses: []
42
+
43
+ post_install_message:
44
+ rdoc_options: []
45
+
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 0
55
+ version: "0"
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project: grabbio
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: A ruby wrapper for the grabbio platform
71
+ test_files: []
72
+