Permalink
Browse files

inital commit

  • Loading branch information...
0 parents commit 433471a4fc78149ba85905482818870c21d41b2f Jake Yesbeck committed Jul 16, 2012
Showing with 124 additions and 0 deletions.
  1. +8 −0 .gitignore
  2. +4 −0 Gemfile
  3. +1 −0 Rakefile
  4. +7 −0 lib/yesmail.rb
  5. +19 −0 lib/yesmail/configuration.rb
  6. +18 −0 lib/yesmail/poster.rb
  7. +37 −0 lib/yesmail/subscriber.rb
  8. +3 −0 lib/yesmail/version.rb
  9. +27 −0 yesmail.gemspec
@@ -0,0 +1,8 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
+spec/*
+.rvmrc
+.rspec
+.idea/*
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in yesmail.gemspec
+gemspec
@@ -0,0 +1 @@
+require "bundler/gem_tasks"
@@ -0,0 +1,7 @@
+require 'yesmail/version'
+require 'yesmail/poster'
+require 'yesmail/subscriber'
+require 'yesmail/configuration'
+module Yesmail
+
+end
@@ -0,0 +1,19 @@
+module Yesmail
+ class Configuration
+ def username
+ global_config[:yesmail][:username] if global_config
+ end
+
+ def password
+ global_config[:yesmail][:password] if global_config
+ end
+
+ def global_config
+ @config ||= begin
+ Rails.application.config
+ rescue NameError
+ #we are not using rails, do nothing
+ end
+ end
+ end
+end
@@ -0,0 +1,18 @@
+require 'httparty'
+module Yesmail
+ class Poster
+ include HTTParty
+ debug_output $stderr
+
+ base_uri 'https://services.yesmail.com/enterprise'
+
+ def initialize(u, p)
+ @auth = { username: u, password: p }
+ end
+
+ def post(post_data, path)
+ options = { basic_auth: @auth, :body => post_data}
+ self.class.post(path, options)
+ end
+ end
+end
@@ -0,0 +1,37 @@
+require 'json'
+module Yesmail
+ class Subscriber
+ attr_accessor :email, :name
+
+ def make_hash
+ data_hash = {
+ subscriptionState: "SUBSCRIBED",
+ division: { value: "Retail" },
+ attributes: { attributes: [] }
+ }
+
+ data.each do |key, value|
+ data_hash[:attributes][:attributes] << { name: key, value: value }
+ end
+
+ JSON(data_hash)
+ end
+
+ def data
+ {
+ email: email,
+ name: name
+ }
+ end
+
+ def config
+ @config ||= Configuration.new
+ end
+
+ def api_create
+ handler = Poster.new(config.username, config.password)
+ path = '/subscribers'
+ handler.post(make_hash, path)
+ end
+ end
+end
@@ -0,0 +1,3 @@
+module Yesmail
+ VERSION = "0.0.1"
+end
@@ -0,0 +1,27 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "yesmail/version"
+
+Gem::Specification.new do |s|
+ s.name = "yesmail"
+ s.version = Yesmail::VERSION
+ s.authors = ["Jake Yesbeck"]
+ s.email = ["jake@verticalbrands.com"]
+ s.homepage = ""
+ s.summary = %q{TODO: Write a gem summary}
+ s.description = %q{TODO: Write a gem description}
+
+ s.rubyforge_project = "yesmail"
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+
+ # specify any dependencies here; for example:
+ # s.add_development_dependency "rspec"
+ # s.add_runtime_dependency "rest-client"
+ s.add_dependency 'httparty'
+ s.add_development_dependency 'rspec'
+ s.add_development_dependency 'rr'
+end

0 comments on commit 433471a

Please sign in to comment.