├── .gitignore ├── Gemfile ├── Gemfile.lock ├── LICENSE.txt ├── README.md ├── Rakefile ├── lib ├── loklak.rb └── loklak │ └── version.rb └── loklak.gemspec /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | /.config 4 | /coverage/ 5 | /InstalledFiles 6 | /pkg/ 7 | /spec/reports/ 8 | /spec/examples.txt 9 | /test/tmp/ 10 | /test/version_tmp/ 11 | /tmp/ 12 | 13 | ## Specific to RubyMotion: 14 | .dat* 15 | .repl_history 16 | build/ 17 | 18 | ## Documentation cache and generated files: 19 | /.yardoc/ 20 | /_yardoc/ 21 | /doc/ 22 | /rdoc/ 23 | 24 | ## Environment normalisation: 25 | /.bundle/ 26 | /vendor/bundle 27 | /lib/bundler/man/ 28 | 29 | # for a library or gem, you might want to ignore these files since the code is 30 | # intended to run in multiple environments; otherwise, check them in: 31 | # Gemfile.lock 32 | # .ruby-version 33 | # .ruby-gemset 34 | 35 | # unless supporting rvm < 1.11.0 or doing something fancy, ignore this: 36 | .rvmrc 37 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # Specify your gem's dependencies in loklak.gemspec 4 | gemspec 5 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | loklak (0.0.1) 5 | 6 | GEM 7 | remote: https://rubygems.org/ 8 | specs: 9 | rake (10.4.2) 10 | 11 | PLATFORMS 12 | ruby 13 | 14 | DEPENDENCIES 15 | bundler (~> 1.7) 16 | loklak! 17 | rake (~> 10.0) 18 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Seva Zhidkov 2 | 3 | MIT License 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 20 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 22 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Loklak 2 | 3 | [![Dependency Status](https://gemnasium.com/badges/github.com/loklak/loklak_ruby_api.svg)](https://gemnasium.com/github.com/loklak/loklak_ruby_api) 4 | 5 | Ruby wrapper for loklak.org API - [distributed tweet search server](https://github.com/loklak/loklak_server) 6 | 7 | ## Installation 8 | 9 | Add this line to your application's Gemfile: 10 | 11 | ```ruby 12 | gem 'loklak' 13 | ``` 14 | 15 | And then execute: 16 | ``` 17 | bundle 18 | ``` 19 | 20 | Or install it yourself as: 21 | ``` 22 | gem install loklak 23 | ``` 24 | 25 | ## Usage 26 | ``` 27 | require 'loklak' 28 | ``` 29 | ### Hello 30 | ``` 31 | Loklak.hello() 32 | ``` 33 | ### Status 34 | ``` 35 | Loklak.status() 36 | ``` 37 | ## Contact 38 | Send me a message in Telegram: [@sevazhidkov](https://telegram.me/sevazhidkov). 39 | 40 | Or in Twitter: [@sevazhidkov](https://twitter.com/sevazhidkov). 41 | 42 | Or E-mail: [zhidkovseva@gmail.com](mailto:zhidkovseva@gmail.com). 43 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'bundler/gem_tasks' 2 | -------------------------------------------------------------------------------- /lib/loklak.rb: -------------------------------------------------------------------------------- 1 | require 'net/http' 2 | require 'json' 3 | require 'loklak/version' 4 | require 'open-uri' 5 | 6 | BASE_API_URL = 'http://api.loklak.org/api/'.freeze 7 | 8 | def api_call(method_path = nil) 9 | return {} if method_path.nil? 10 | response = Net::HTTP.get_response(URI(URI.encode(BASE_API_URL + 11 | method_path))) 12 | if response.code == '200' 13 | JSON.parse(response.body) 14 | else 15 | {} 16 | end 17 | end 18 | 19 | # Module to access loklak apis 20 | module Loklak 21 | def self.hello 22 | method_path = 'hello.json' 23 | api_call(method_path) 24 | end 25 | 26 | def self.status 27 | method_path = 'status.json' 28 | api_call(method_path) 29 | end 30 | 31 | def self.search(query = nil, since_date = nil, until_date = nil, 32 | from_user = nil, count = nil) 33 | method_path = 'search.json' 34 | return {} if query.nil? 35 | method_path += '?query=' + query 36 | method_path += ' since:' + since_date unless since_date.nil? 37 | method_path += ' until:' + until_date unless until_date.nil? 38 | method_path += ' from:' + from_user unless from_user.nil? 39 | method_path += '&count=' + count.to_s unless count.nil? 40 | puts method_path 41 | api_call(method_path) 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /lib/loklak/version.rb: -------------------------------------------------------------------------------- 1 | module Loklak 2 | VERSION = '0.0.2'.freeze 3 | end 4 | -------------------------------------------------------------------------------- /loklak.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | lib = File.expand_path('../lib', __FILE__) 4 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 5 | require 'loklak/version' 6 | 7 | Gem::Specification.new do |spec| 8 | spec.name = 'loklak' 9 | spec.version = Loklak::VERSION 10 | spec.authors = ['Seva Zhidkov'] 11 | spec.email = ['zhidkovseva@gmail.com'] 12 | spec.summary = '{Ruby wrapper for loklak.org API - 13 | distributed tweet search server}' 14 | spec.description = '{Ruby wrapper for loklak.org API - 15 | distributed tweet search server}' 16 | spec.homepage = 'https://github.com/sevazhidkov/ruby-loklak-api' 17 | spec.license = 'MIT' 18 | 19 | spec.files = `git ls-files -z`.split("\x0") 20 | spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } 21 | spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) 22 | spec.require_paths = ['lib'] 23 | 24 | spec.add_development_dependency 'bundler', '~> 1.7' 25 | spec.add_development_dependency 'rake', '~> 10.0' 26 | end 27 | --------------------------------------------------------------------------------