Code Monkey home page Code Monkey logo

apist's Introduction

SleepingOwl Apist

Build Status Latest Stable Version Total Downloads License Code Climate

SleepingOwl Apist is a small library which allows you to access any site in api-like style, based on html parsing.

Overview

This package allows you to write method like this:

class WikiApi extends Apist
{

	public function getBaseUrl()
	{
		return 'http://en.wikipedia.org';
	}

	public function index()
	{
		return $this->get('/wiki/Main_Page', [
			'welcome_message'  => Apist::filter('#mp-topbanner div:first')->text()->mb_substr(0, -1),
			'portals'          => Apist::filter('a[title^="Portal:"]')->each([
				'link'  => Apist::current()->attr('href')->call(function ($href)
				{
					return $this->getBaseUrl() . $href;
				}),
				'label' => Apist::current()->text()
			]),
			'languages'        => Apist::filter('#p-lang li a[title]')->each([
				'label' => Apist::current()->text(),
				'lang'  => Apist::current()->attr('title'),
				'link'  => Apist::current()->attr('href')->call(function ($href)
				{
					return 'http:' . $href;
				})
			]),
			'sister_projects'  => Apist::filter('#mp-sister b a')->each()->text(),
			'featured_article' => Apist::filter('#mp-tfa')->html()
		]);
	}
}

and get the following result:

{
    "welcome_message": "Welcome to Wikipedia",
    "portals": [
        {
            "link": "http:\/\/en.wikipedia.org\/wiki\/Portal:Arts",
            "label": "Arts"
        },
        {
            "link": "http:\/\/en.wikipedia.org\/wiki\/Portal:Biography",
            "label": "Biography"
        },
        ...
    ],
    "languages": [
        {
            "label": "Simple English",
            "lang": "Simple English",
            "link": "http:\/\/simple.wikipedia.org\/wiki\/"
        },
        {
            "label": "العربية",
            "lang": "Arabic",
            "link": "http:\/\/ar.wikipedia.org\/wiki\/"
        },
        {
            "label": "Bahasa Indonesia",
            "lang": "Indonesian",
            "link": "http:\/\/id.wikipedia.org\/wiki\/"
        },
        ...
    ],
    "sister_projects": [
        "Commons",
        "MediaWiki",
        ...
    ],
    "featured_article": "<div style=\"float: left; margin: 0.5em 0.9em 0.4em 0em;\">...<\/div>"
}

Installation

Require this package in your composer.json and run composer update (or run composer require sleeping-owl/apist:1.x directly):

	"sleeping-owl/apist": "1.*"

Documentation

Documentation can be found at sleeping owl apist.

Examples

View examples.

Support Library

You can donate via PayPal, Yandex money (410012943296949) or in BTC: 13k36pym383rEmsBSLyWfT3TxCQMN2Lekd

Copyright and License

Apist was written by Sleeping Owl and is released under the MIT License. See the LICENSE file for details.

apist's People

Contributors

sleeping-owl avatar zamarawka avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.