Coder Social home page Coder Social logo

ruby-sdk's Introduction

Constant Contact Ruby SDK for AppConnect

The Ruby SDK for AppConnect allows you to leverage the AppConnect v2 APIs.

Build Status

Installation

Via bundler:

gem 'constantcontact', '~> 2.2.0'

Otherwise:

[sudo|rvm] gem install constantcontact

Configuration

The AppConnect SDK can be configured with some options globally or they can be specified when creating the API client:

ConstantContact::Util::Config.configure do |config|
  config[:auth][:api_key] = 'your-access-key'
  config[:auth][:api_secret] = 'your-access-secret'
  config[:auth][:redirect_uri] = 'https://example.com/auth/constantcontact'
end

Documentation

SDK Documentation is hosted at http://constantcontact.github.io/ruby-sdk

API Documentation is located at http://developer.constantcontact.com/docs/developer-guides/api-documentation-index.html

Getting Started

AppConnect requires an OAuth access token which will give your app access to Constant Contact data and services for the accout that granted that access token.

Rails

Create a new controller action. The redirect_url should be the same as the one given when registering the app with Mashery. Use the following code snippet to get an access token:

@oauth = ConstantContact::Auth::OAuth2.new(
  :api_key => 'your api key',
  :api_secret => 'your secret key',
  :redirect_url => 'your redirect url' # the URL given when registering your app with Mashery.
)

@error = params[:error]
@user = params[:username]
@code = params[:code]

if @code.present?
  response = @oauth.get_access_token(@code)
  if response.present?
    token = response['access_token']
    cc = ConstantContact::Api.new('your api key', token)
    @contacts = cc.get_contacts()
  end
else
  # if not code param is provided redirect into the OAuth flow
  redirect_to @oauth.get_authorization_url and return
end

Create a view for the above mentioned action with the following code:


<% if @error %>
  <p><%= @error %></p>
<% end %>

<% if @contacts.present? %>
  <% @contacts.results.each do |contact| %>
    <p>Contact name: <%= "#{contact.first_name} #{contact.last_name}" %></p>
  <% end %>
<% end %>

The first time you access the action you will be redirected into the Constant Contact OAuth flow. Then you will be redirected back to your action and you should see the list of contacts.

Sinatra

Require AppConnect:

require 'constantcontact'

Add the following route. The redirect_url should be the same given when registering the app with Mashery.

get '/my_url' do
  @oauth = ConstantContact::Auth::OAuth2.new(
    :api_key => 'your api key',
    :api_secret => 'your secret key',
    :redirect_url => 'your redirect url'
  )

  @error = params[:error]
  @user = params[:username]
  @code = params[:code]

  if @code
    response = @oauth.get_access_token(@code)
    if response
      token = response['access_token']
      cc = ConstantContact::Api.new('your api key', token)
      @contacts = cc.get_contacts()
    end
  end

  erb :my_view
end

Create a my_view.erb with the following code:

<% if @error %>
  <p><%=@error%></p>
<% end %>

<% if @code %>
  <% if @contacts %>
    <% @contacts.results.each do |contact| %>
      <p>\Contact name: <%= "#{contact.first_name} #{contact.last_name}" %></p>
    <% end %>
  <% end %>
<% else %>
  <a href="<%[email protected]_authorization_url%>">Click to authorize</a>
<% end %>

The first time you access the action in browser you should see the "Click to authorize" link. Follow the link, go through all the Constant Contact steps required and then you will be redirected back to your action and you should see the list of contacts.

ruby-sdk's People

Contributors

sioachim avatar csciuto avatar innonagle avatar dsjellz avatar aguriuc avatar shannon7wallace avatar gshiftlabs-dbuttineau avatar egaiter avatar gshiftlabs-jsteel avatar mapalumbo avatar alexandru1 avatar derekyau avatar jorge8989 avatar richm541 avatar

Watchers

James Cloos 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.