-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
169 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |