Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

any_api

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

any_api

  • 0.0.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

AnyApi is the worlds smallest API client :-)

Decided to share this thanks to some research I did on APIs. Most of them have a base URL, then API endpoint, API username, a API password and transmits data in form of JSON. Then there are requests and responses. This could be a simple solution to access and work with a big or small APIs.

Please give Ruby's Net::HTTP Library a go. That is the backbone behind this. Net::HTTP simple, does the job, it is fast and build on top Ruby's IO so straight to the point.

Installation

gem 'any_api'

And then execute:

$ bundle

Or install it yourself as:

$ gem install any_api

Usage

If you are going to use this with Rails. Add bellow code your application.rb file, or the application_controller.rb file or as an initialiser file. It would work fine with any other Ruby project.

AnyApi.configure do |config|
  #please dont put a "/" at the end of the api_base_url
  config.api_base_url =  "https://iamfree.com/api/v1"
  #Dont need bellow authentication information if the API does not need username and password  
  config.username =  "me@example.com"
  config.password =  "my-sectret-password"
end

Then you can call any API with

response = AnyApi::Request.new("Get", 'products.json' )

The first parameter is the HTTP method. Secondly it is the url endpoint.

If you want to do Post or Update calls please send parameters with your request

my_params = {"year"=>"2014", "country"=>"Australia", "first_name"=>"True", "last_name"=>"Colours"}
response = AnyApi::Request.new( "Post", 'users/new', my_params)

To parse the response

response.parser_response

If you want assert that the API call is a success before save your information database you could use the is_ok? method

  if response.is_ok?
    good_json = response.parser_response
    ......
  else
    bad_json_error_message = response.parser_response
    .....
  end


Thanks

Contributing

  1. Fork it ( https://github.com/iamfree-com/any_api/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

FAQs

Package last updated on 10 Dec 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc