All Projects → sparkapi → Spark_api

sparkapi / Spark_api

Licence: other
Ruby client library for communication with the Spark API

Programming Languages

ruby
36898 projects - #4 most used programming language

Labels

Projects that are alternatives of or similar to Spark api

Strip attributes
🔪 An ActiveModel extension that automatically strips all attributes of leading and trailing whitespace before validation. If the attribute is blank, it strips the value to nil.
Stars: ✭ 441 (+687.5%)
Mutual labels:  rubygem
Ordinalize full
Turns a number into an ordinal string such as first, second, third or 1st, 2nd, 3rd.
Stars: ✭ 6 (-89.29%)
Mutual labels:  rubygem
Rom Elasticsearch
Elasticsearch adapter for rom-rb
Stars: ✭ 30 (-46.43%)
Mutual labels:  rubygem
Matestack Ui Core
Matestack enables you to create sophisticated, reactive UIs in pure Ruby, without touching JavaScript and HTML. You end up writing 50% less code while increasing productivity, maintainability and developer happiness.
Stars: ✭ 469 (+737.5%)
Mutual labels:  rubygem
Scientist
🔬 A Ruby library for carefully refactoring critical paths.
Stars: ✭ 6,301 (+11151.79%)
Mutual labels:  rubygem
App store connect
A Ruby interface to the App Store Connect API
Stars: ✭ 22 (-60.71%)
Mutual labels:  rubygem
Gemoji
Emoji images and names.
Stars: ✭ 3,890 (+6846.43%)
Mutual labels:  rubygem
Tty Font
Terminal fonts
Stars: ✭ 44 (-21.43%)
Mutual labels:  rubygem
Materialize Sass
Materializecss rubygem for Rails Asset Pipeline / Sprockets
Stars: ✭ 785 (+1301.79%)
Mutual labels:  rubygem
Sql Composer
Standalone SQL composer DSL for Ruby
Stars: ✭ 26 (-53.57%)
Mutual labels:  rubygem
Gingerice
Ruby wrapper for correcting spelling and grammar mistakes based on the context of complete sentences.
Stars: ✭ 478 (+753.57%)
Mutual labels:  rubygem
Runbook
A framework for gradual system automation
Stars: ✭ 531 (+848.21%)
Mutual labels:  rubygem
Human name parser
A name parsing library
Stars: ✭ 7 (-87.5%)
Mutual labels:  rubygem
Dry Monads
Useful, common monads in idiomatic Ruby
Stars: ✭ 453 (+708.93%)
Mutual labels:  rubygem
Kraken Ruby
Official Ruby Gem for Kraken API
Stars: ✭ 34 (-39.29%)
Mutual labels:  rubygem
Ruby Push Notifications
iOS, Android and Windows Phone Push Notifications made easy!!
Stars: ✭ 385 (+587.5%)
Mutual labels:  rubygem
Green Button Data
Fast Ruby parser and API client for Green Button data
Stars: ✭ 18 (-67.86%)
Mutual labels:  rubygem
Dry Validation
Validation library with type-safe schemas and rules
Stars: ✭ 1,087 (+1841.07%)
Mutual labels:  rubygem
Fastlane Plugin Google drive
fastlane plugin to upload files to Google Drive
Stars: ✭ 39 (-30.36%)
Mutual labels:  rubygem
Sense Client
Quick and dirty Ruby client for the Hello Sense sleep tracker. Based on http://jeffhuang.com/extracting_my_data_from_the_hello_sense.html
Stars: ✭ 20 (-64.29%)
Mutual labels:  rubygem

Spark API

CI Code Climate

A Ruby wrapper for the Spark REST API. Loosely based on ActiveResource to provide models to interact with remote services.

Documentation

For further client documentation, please consult our wiki.

For full information on the API, see http://sparkplatform.com/docs/overview/api

Installation

gem install spark_api

Usage Examples

require 'spark_api'
SparkApi.configure do |config|
  config.endpoint   = 'https://sparkapi.com'
  # Using Spark API Authentication, refer to the Authentication documentation for OAuth2
  config.api_key    = 'MY_SPARK_API_KEY'
  config.api_secret = 'MY_SPARK_API_SECRET'
end
SparkApi.client.get '/my/account'

Interactive Console

Included in the gem is an interactive spark_api console to interact with the api in a manner similar to the rails console. Below is a brief example of interacting with the console:

> spark_api --api_key MY_SPARK_API_KEY --api_secret MY_SPARK_API_SECRET
SparkApi> SparkApi.client.get '/my/account'

Using OAuth2 requires different arguments, and is a bit more complicated as it requires a step for logging in through the browser to gain access to the access code for a client_id.

> bundle exec spark_api --oauth2 --client_id my_oauth2_client_id --client_secret my_oauth2_client_secret 
Loading spark_api gem...
SparkApi:001:0> Account.my.Name
Missing OAuth2 session, redirecting...
Please visit https://sparkplatform.com/oauth2?client_id=my_oauth2_client_id&response_type=code&redirect_uri=https%3A%2F%2Fsparkplatform.com%2Foauth2%2Fcallback, login as a user, and paste the authorization code here:
Authorization code?
9zsrc7jk7m4x7r4kers8n6sp5
"Demo User"
SparkApi:002:0> Account.my.UserType
"Member"

You can also provide other options from the command line, see "spark_api -h" for more information.

HTTP Interface

The base client provides a bare bones HTTP interface for working with the RESTful Spark API. This is basically a stylized curl interface that handles authentication, error handling, and processes JSON results as Ruby Hashes.

SparkApi.client.get     "/listings/#{listing_id}", :_expand => "CustomFields"
SparkApi.client.post    "/listings/#{listing_id}/photos", photo_body_hash
SparkApi.client.put     "/listings/#{listing_id}/photos/#{photo_id}", updated_photo_name_hash
SparkApi.client.delete  "/listings/#{listing_id}/photos/#{photo_id}"

API Models

The client also provides ActiveModelesque interface for working with the api responses. Notably, the models use finder methods for searching, and similar instanciation and persistence also on supported services.

# Tip: mixin the models so you can use them without namespaces
include SparkApi::Models
listings = Listing.find(:all, :_filter => "ListPrice Gt 150000.0 And ListPrice Lt 200000.0", :_orderby => "-ListPrice")
puts "Top list price: $%.2f" % listings.first.ListPrice

# Top list price: $199999.99
puts Account.find(:first, :_filter => "UserType Eq 'Member' And Name Eq 'John*'").Name
# John Doe

JSON Parsing

By default, this gem uses the pure ruby json gem for parsing API responses for cross platform compatibility. Projects that include the yajl-ruby gem will see noticeable speed improvements when installed.

Authentication Types

Authentication is handled transparently by the request framework in the gem, so you should never need to manually make an authentication request. More than one mode of authentication is supported, so the client needs to be configured accordingly.

Spark API Authentication (Default)

Usually supplied for a single user, this authentication mode is the simplest, and is setup as the default. The example usage above demonstrates how to get started using this authentication mode.

OpenId/OAuth2 Combined Flow (Preferred)

Authorization mode the separates application and user authentication. This mode requires the end user to be redirected to Spark Platform's openid endpoint. See "script/combined_flow_example.rb" for an example.

Read more about Spark Platform's combined flow here.

OAuth2 Authorization

Authorization mode the separates application and user authentication. This mode requires the end user to be redirected to Spark Platform's auth endpoint. See "script/oauth2_example.rb" for an example.

Read more about Spark Platform's OAuth 2 flow here.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].