newsletter7_api 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3284c30e56d4e70c3f4ebd0eee84670c97c02c0b
4
+ data.tar.gz: 1b01a9c23cfcf5416886494f77c39e22ef90cb89
5
+ SHA512:
6
+ metadata.gz: 487f70c8a71847c7dca47d9d337a4552c158db75172dcc5f7f6aedda42f9c7276a31e51a80a2c6be0bab9fbe656846b7a1f4611167dcfdbf01b3f218c6cbc633
7
+ data.tar.gz: 1376387e69529b71706e85a94aeb8135781355d5ac36ee903a4ac8324d368676eeea582dc5d250ee6916896405db0342b03bd0b26289c0ed44ffd711df4f6eb0
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --warnings
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in newsletter7_api.gemspec
4
+ gemspec
5
+
6
+ gem 'rails', group: :test
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 siera
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,124 @@
1
+ # Newsletter7Api
2
+
3
+ This is a API interface to export email contact_group to Newsletter7. Accounts signed up Newsletter7 with Bonofa account can export Newsletter7 email contact_group directly on Bonofa sites.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'newsletter7_api'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install newsletter7_api
18
+
19
+ ## Usage
20
+
21
+ You can use ContactGroup resources as normal models.
22
+
23
+ ```ruby
24
+ Newsletter7ApiResource.connection.set_header('ACCESS_TOKEN', account_promotion_code)
25
+ @contact_group = Newsletter7Api::ContactGroup.new(name: '', contacts: [])
26
+
27
+ @your_contact_group = ...
28
+ @your_contact_group.each do |member|
29
+ @contact_group.contacts << member
30
+ end
31
+
32
+ @contact_group.save
33
+ ```
34
+
35
+ This will create a contact_group on Newsletter7.(Imagine memeber has attributes first_name, last_name, email)
36
+
37
+ ### Configuration
38
+
39
+ You can configure Newsletter7 api url and http authentication name and password in initializer(config/initializers/newsletter7_api.rb)
40
+
41
+ ```ruby
42
+ Newsletter7ApiResource.site = 'http://localhost:3000/api/v1'
43
+ Newsletter7ApiResource.user = 'newsletter7'
44
+ Newsletter7ApiResource.password = 'defaultpw'
45
+ ```
46
+
47
+ This settings should be match with those of Newsletter7.
48
+
49
+ Account promotion code will be encrypted and set in request header as access token. This promotion code will be used to find Newsletter7 account.
50
+
51
+
52
+ ### Using Example
53
+
54
+ Coltroller code can be look like this;
55
+
56
+ ```ruby
57
+ class ContactGroupsController < ApplicationController
58
+
59
+ newsletter7_api
60
+
61
+ def new
62
+ begin
63
+ @contact_group = Newsletter7Api::ContactGroup.all
64
+ rescue => e
65
+ redirect_to root_path, alert: 'You are not authorized to access Newsletter7.'
66
+ return
67
+ end
68
+
69
+ @your_contact_group = ...
70
+
71
+ @your_contact_group.each do |member|
72
+ @contact_group.contacts << member
73
+ end
74
+ end
75
+
76
+ def create
77
+ @contact_group = Newsletter7Api::ContactGroup.new(params[:newsletter7_api_contact_group])
78
+
79
+ if @contact_group.save
80
+ redirect_to root_path, notice: 'Contacts were successfully exported.'
81
+ else
82
+ redirect_to root_path, alert: 'Error occured while exporting contacts.'
83
+ end
84
+ end
85
+ end
86
+ ```
87
+
88
+ Form example(haml)
89
+
90
+ ```ruby
91
+ = form_for(@contact_group, url: url_for(:action => 'create')) do |f|
92
+ %fieldset
93
+ = f.label :name
94
+ = f.text_field :name
95
+
96
+ %h4
97
+ Contacts to export
98
+ %small (member with invalid email or not selected will not be exported.)
99
+ = render partial: 'contact', collection: @contact_group.contacts
100
+
101
+ = f.submit
102
+ ```
103
+
104
+ Contact partial
105
+
106
+ ```ruby
107
+ .contact_field
108
+ %fieldset
109
+ = text_field_tag "newsletter7_api_contact_group[contacts][][first_name]", contact.first_name, placeholder: 'First Name'
110
+ %fieldset
111
+ = text_field_tag "newsletter7_api_contact_group[contacts][][last_name]", contact.last_name, placeholder: 'Last Name'
112
+ %fieldset
113
+ = text_field_tag "newsletter7_api_contact_group[contacts][][email]", contact.email, placeholder: 'Email'
114
+ %fieldset
115
+ = check_box_tag "newsletter7_api_contact_group[contacts][][selected]", true, checked: true
116
+ ```
117
+
118
+ ## Contributing
119
+
120
+ 1. Fork it ( https://github.com/c7devteam/newsletter7_api/fork )
121
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
122
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
123
+ 4. Push to the branch (`git push origin my-new-feature`)
124
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ require 'bundler'
@@ -0,0 +1,19 @@
1
+ module Newsletter7ApiController
2
+
3
+ module ClassMethods
4
+
5
+ def newsletter7_api(opts={})
6
+ before_filter { generate_access_token(opts) }
7
+ end
8
+ end
9
+
10
+
11
+ module InstanceMethods
12
+
13
+ private
14
+
15
+ def generate_access_token(opts={})
16
+ Newsletter7ApiResource.connection.set_header('ACCESS_TOKEN', current_account.promotion_code)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ require "newsletter7_api/version"
2
+ require "newsletter7_api/newsletter7_api_resource"
3
+ require "newsletter7_api/contact_group"
4
+ require "newsletter7_api/engine"
@@ -0,0 +1,7 @@
1
+ module Newsletter7Api
2
+
3
+ class ContactGroup < Newsletter7ApiResource
4
+
5
+ end
6
+ end
7
+
@@ -0,0 +1,13 @@
1
+ module Newsletter7Api
2
+
3
+ class Engine < ::Rails::Engine
4
+
5
+ initializer 'newsletter7_api.controller' do
6
+
7
+ ActiveSupport.on_load(:action_controller) do
8
+ include Newsletter7ApiController::InstanceMethods
9
+ extend Newsletter7ApiController::ClassMethods
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,18 @@
1
+ require 'active_resource'
2
+ require 'encryptor'
3
+
4
+
5
+ class Newsletter7ApiResource < ActiveResource::Base
6
+ self.site = "http://localhost:3000/api/v1"
7
+ self.user = "newsletter7"
8
+ self.password = "defaultpw"
9
+ end
10
+
11
+
12
+ class ActiveResource::Connection
13
+ alias :static_default_header :default_header
14
+
15
+ def set_header(key, value)
16
+ default_header.update(key => Base64.encode64(Encryptor.encrypt(value: value, key: Newsletter7ApiResource.password)))
17
+ end
18
+ end
@@ -0,0 +1,4 @@
1
+ module Newsletter7Api
2
+
3
+ VERSION = "0.1.1"
4
+ end
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'newsletter7_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "newsletter7_api"
8
+ spec.version = Newsletter7Api::VERSION
9
+ spec.authors = ["siera"]
10
+ spec.email = ["sieraruo@gmail.com"]
11
+ spec.summary = %q{Newsletter7 API client}
12
+ spec.description = %q{Newsletter7 API client can export contacts to Newsletter7 site easily using newsletter7_api}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'activeresource', '~> 4.0', '>= 4.0.0'
22
+ spec.add_runtime_dependency 'encryptor', '~> 1.3', '>= 1.3.0'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.6"
25
+ spec.add_development_dependency 'rspec'
26
+ end
@@ -0,0 +1,54 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+
4
+ describe "Newsletter7Api" do
5
+
6
+ describe "Newsletter7ApiResource" do
7
+
8
+ it "should set site" do
9
+ expect(Newsletter7ApiResource.site.to_s).to eq('http://localhost:3000/api/v1')
10
+ end
11
+
12
+ it "should set user" do
13
+ expect(Newsletter7ApiResource.user).to eq('newsletter7')
14
+ end
15
+
16
+ it "should set password" do
17
+ expect(Newsletter7ApiResource.password).to eq('defaultpw')
18
+ end
19
+ end
20
+
21
+ describe "ContactGroup" do
22
+
23
+ before do
24
+ @contact_groups = [{ name: 'Bonofa Group', description: 'test' }].to_json
25
+ @contact_group = { name: 'Bonofa Group', contacts: [{first_name: 'first_name', last_name: 'last_name', email: 'test@test.com'}] }.to_json
26
+
27
+ ActiveResource::HttpMock.respond_to do |mock|
28
+ mock.get "/api/v1/contact_groups.json", {"Authorization"=>"Basic bmV3c2xldHRlcjc6ZGVmYXVsdHB3", "Accept"=>"application/json"}, @contact_groups
29
+ mock.post "/api/v1/contact_groups.json", {"Authorization"=>"Basic bmV3c2xldHRlcjc6ZGVmYXVsdHB3", "Content-Type"=>"application/json"}, @contact_group, 201
30
+ end
31
+ end
32
+
33
+ it "should fetch contact groups" do
34
+ contact_groups = Newsletter7Api::ContactGroup.all
35
+ expect(contact_groups).to be_a(ActiveResource::Collection)
36
+ end
37
+
38
+ it "should save contacts" do
39
+ contact_group = Newsletter7Api::ContactGroup.new({name: 'Bonofa Group', contacts: [{first_name: 'first_name', last_name: 'last_name', email: 'test@test.com'}]})
40
+ contact_group.save
41
+ expect(contact_group.name).to eq('Bonofa Group')
42
+ end
43
+ end
44
+
45
+ describe "Controller" do
46
+
47
+ describe "before filter" do
48
+
49
+ it "should generate access token in header" do
50
+ expect(Newsletter7ApiResource.connection.set_header('ACCESS_TOKEN', 'promotion_code')).to eq({"ACCESS_TOKEN"=>"#{Base64.encode64(Encryptor.encrypt(value: 'promotion_code', key: 'defaultpw'))}"})
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,6 @@
1
+ require 'rails'
2
+ require 'newsletter7_api'
3
+
4
+ RSpec.configure do |config|
5
+
6
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: newsletter7_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - siera
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activeresource
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 4.0.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 4.0.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: encryptor
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.3'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 1.3.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '1.3'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 1.3.0
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: '1.6'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: '1.6'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rspec
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ description: Newsletter7 API client can export contacts to Newsletter7 site easily
82
+ using newsletter7_api
83
+ email:
84
+ - sieraruo@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - ".gitignore"
90
+ - ".rspec"
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - app/controllers/newsletter7_api_controller.rb
96
+ - lib/newsletter7_api.rb
97
+ - lib/newsletter7_api/contact_group.rb
98
+ - lib/newsletter7_api/engine.rb
99
+ - lib/newsletter7_api/newsletter7_api_resource.rb
100
+ - lib/newsletter7_api/version.rb
101
+ - newsletter7_api.gemspec
102
+ - spec/newsletter7_api_spec.rb
103
+ - spec/spec_helper.rb
104
+ homepage: ''
105
+ licenses:
106
+ - MIT
107
+ metadata: {}
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ requirements:
119
+ - - ">="
120
+ - !ruby/object:Gem::Version
121
+ version: '0'
122
+ requirements: []
123
+ rubyforge_project:
124
+ rubygems_version: 2.4.1
125
+ signing_key:
126
+ specification_version: 4
127
+ summary: Newsletter7 API client
128
+ test_files:
129
+ - spec/newsletter7_api_spec.rb
130
+ - spec/spec_helper.rb
131
+ has_rdoc: