Skip to content

Commit

Permalink
💥
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmetabdi committed Apr 24, 2015
1 parent e244ae4 commit 84fc621
Show file tree
Hide file tree
Showing 9 changed files with 169 additions and 2 deletions.
19 changes: 19 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PATH
remote: .
specs:
alluc (0.1.0)
excon

GEM
remote: https://rubygems.org/
specs:
excon (0.44.4)
rake (10.4.2)

PLATFORMS
ruby

DEPENDENCIES
alluc!
bundler (~> 1.8)
rake (~> 10.0)
4 changes: 4 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
require "bundler/gem_tasks"

desc "Open an irb session preloaded with this library"
task :console do
sh "irb -rubygems -I lib -r alluc.rb"
end
Binary file removed alluc-0.1.0.gem
Binary file not shown.
1 change: 1 addition & 0 deletions alluc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Gem::Specification.new do |spec|

spec.add_development_dependency "bundler", "~> 1.8"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_dependency 'excon'
end
37 changes: 35 additions & 2 deletions lib/alluc.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,38 @@
require "alluc/version"
require 'alluc/version'
require 'excon'
require 'pry'
require 'ostruct'
require 'json'
require 'cgi'
require 'alluc/api'
require 'alluc/requester'

module Alluc
# Your code goes here...

def self.connect(api_key)
Alluc::Api.instance.tap do |api|
api.connect(api_key)
end
end

def self.streaming_links(query, opts={})
params = Hash.new.tap do |hash|
hash['query'] = CGI.escape(query)
hash['count'] = opts[:count] if opts[:count] # count - max-amount of returned results. Can be between 1 - 100
hash['from'] = opts[:from] if opts[:from] # from - where to start. For example if you want result 20-30, you will set count=10 and from=20
hash['getmeta'] = opts[:getmeta] if opts[:getmeta] # getmeta - If you want additional info on hosterlinks and source, set this to 1. Only use if you really need it as it might make for slower queries.
end
Alluc::Requester.get('search/stream', params)
end

def self.download_links(query, opts={})
params = Hash.new.tap do |hash|
hash['query'] = CGI.escape(query)
hash['count'] = opts[:count] if opts[:count] # count - max-amount of returned results. Can be between 1 - 100
hash['from'] = opts[:from] if opts[:from] # from - where to start. For example if you want result 20-30, you will set count=10 and from=20
hash['getmeta'] = opts[:getmeta] if opts[:getmeta] # getmeta - If you want additional info on hosterlinks and source, set this to 1. Only use if you really need it as it might make for slower queries.
end
Alluc::Requester.get('search/download', params)
end

end
29 changes: 29 additions & 0 deletions lib/alluc/api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'singleton'

module Alluc
class Api
include Singleton

attr_reader :base_url, :mashape_url, :version, :api_key

def initialize
self.base_url = 'https://www.alluc.com/api/'.freeze
self.mashape_url = 'https://alluc-alluc-video-and-download-search-v1.p.mashape.com/api/'.freeze
self.version = '0.1'.freeze
end

def connect(api_key)
self.api_key = api_key
end

def url_for(action, params={})
url = URI.join(mashape_url, action) # Need some base_url / mashape_url logic here
url.query = URI.encode_www_form(params) unless params.empty?
url.to_s
end

private
attr_writer :base_url, :mashape_url, :version, :api_key

end
end
38 changes: 38 additions & 0 deletions lib/alluc/requester.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class Alluc::Requester
class << self
def get(action, params={})
url = api.url_for(action, params)
perform_request do
parse_response(Excon.get(url, :headers => headers))
end
end

private
def api
Alluc::Api.instance
end

def headers
Hash.new.tap do |headers|
headers['Accept'] = 'application/json'
headers['Content-Type'] = 'application/json'
headers['X-Mashape-Key'] = api.api_key
end
end

def perform_request(&block)
begin
block.call
rescue
end
end

def parse_response(response)
begin
JSON.parse(response.body, object_class: OpenStruct)
rescue JSON::ParserError => e
end
end

end
end
32 changes: 32 additions & 0 deletions lib/alluc/search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module Alluc
class Search
# PARAMS: searchtype:string count:number from:number getmeta:number queryL:string (url encoded)
# query - the search string. All alluc search operators can be used (https://www.alluc.com/about/). Make sure to urlencode this.
# count - max-amount of returned results. Can be between 1 - 100.
# from - where to start. For example if you want result 20-30, you will set count=10 and from=20
# apikey - your apikey
# getmeta - If you want additional info on hosterlinks and source, set this to 1. Only use if you really need it as it might make for slower queries.

# "status": "success", // Status, success or error
# "message": "", // What went wrong? empty if success
# "result":[ ] // result of your query. Array when using /api/search/ and object in all other cases.
# "fetchedtoday": 174 // Amount of links retrieved with your apikey so far today
# "resultcount": 1 // Amount of results for the current query

def file_data
# https://www.alluc.com/api/filedata/{filedataid}
# Request more information about a hoster-link. {filedataid} is returned in /api/search/.
end

def source_data
# https://www.alluc.com/api/sourcedata/{md5-of-source-URL}
# Request more information about a source-url (URL where a hoster link was found)
end

def thumbnail
# https://www.alluc.com/api/thumbnail/{imageid}
# Fetch a thumbnail. {imageid} is returned in /api/search/.
end

end
end
11 changes: 11 additions & 0 deletions spec/lib/alluc_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
require 'spec_helper'

describe Alluc::Search do
let!(:search) { Alluc::Search.new('arrow') }

describe '.all' do
it 'should' do
expect(search.all).to eq('x')
end
end
end

0 comments on commit 84fc621

Please sign in to comment.