wildbit-newsberry 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ test/credentials.yml
2
+ pkg
3
+ coverage
@@ -0,0 +1,4 @@
1
+ == 1.0.0 / 2009-04-03
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
@@ -0,0 +1,44 @@
1
+ newsberry
2
+ by Petyo Ivanov <petyo@wildbit.com>
3
+ http://newsberry.com
4
+
5
+ == DESCRIPTION:
6
+
7
+ Simple package that allows you to manage your newsberry contacts.
8
+
9
+ == REQUIREMENTS:
10
+
11
+ * FIXME (list of requirements)
12
+
13
+ == INSTALL:
14
+
15
+ sudo gem install wildbit-newsberry
16
+
17
+ == HOWTO:
18
+
19
+ Check test/newsberry_test.rb for sample usage. It is very basic, and currently SynchronizeSubscribers is implemented only.
20
+
21
+ == LICENSE:
22
+
23
+ (The MIT License)
24
+
25
+ Copyright (c) 2009 Wildbit, LLC
26
+
27
+ Permission is hereby granted, free of charge, to any person obtaining
28
+ a copy of this software and associated documentation files (the
29
+ 'Software'), to deal in the Software without restriction, including
30
+ without limitation the rights to use, copy, modify, merge, publish,
31
+ distribute, sublicense, and/or sell copies of the Software, and to
32
+ permit persons to whom the Software is furnished to do so, subject to
33
+ the following conditions:
34
+
35
+ The above copyright notice and this permission notice shall be
36
+ included in all copies or substantial portions of the Software.
37
+
38
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
39
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
40
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
41
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
42
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
43
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
44
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,48 @@
1
+ # Look in the tasks/setup.rb file for the various options that can be
2
+ # configured in this Rakefile. The .rake files in the tasks directory
3
+ # are where the options are used.
4
+
5
+ require 'rake/testtask'
6
+ require 'rake/rdoctask'
7
+ require 'rcov/rcovtask'
8
+
9
+ begin
10
+ require 'bones'
11
+ Bones.setup
12
+ rescue LoadError
13
+ begin
14
+ load 'tasks/setup.rb'
15
+ rescue LoadError
16
+ raise RuntimeError, '### please install the "bones" gem ###'
17
+ end
18
+ end
19
+
20
+ ensure_in_path 'lib'
21
+ require 'newsberry'
22
+
23
+ task :default => :test
24
+
25
+ desc 'Test the newsberry plugin.'
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = true
30
+ end
31
+
32
+ desc 'Performs code coverage on the newsberry plugin.'
33
+ Rcov::RcovTask.new do |t|
34
+ t.libs << "test"
35
+ t.test_files = FileList['test/*_test.rb']
36
+ t.verbose = true
37
+ end
38
+
39
+ PROJ.name = 'newsberry'
40
+ PROJ.authors = 'Petyo Ivanov'
41
+ PROJ.email = 'petyo@wildbit.com'
42
+ PROJ.url = 'http://newsberry.com'
43
+ PROJ.version = Newsberry::VERSION
44
+ PROJ.rubyforge.name = 'newsberry'
45
+
46
+ PROJ.spec.opts << '--color'
47
+
48
+ # EOF
@@ -0,0 +1,64 @@
1
+
2
+ module Newsberry
3
+
4
+ class << self
5
+ attr_accessor :api_key, :auth
6
+ attr_writer :host
7
+
8
+ # Utility method for configuration. set the _api_key_ here. Optionally, you can set the _host_, by default it is 'newsberry.com'
9
+ #
10
+ def configure
11
+ yield self
12
+ end
13
+
14
+ def host
15
+ @host || 'newsberry.com'
16
+ end
17
+ end
18
+
19
+ # :stopdoc:
20
+ VERSION = '1.0.0'
21
+ LIBPATH = ::File.expand_path(::File.dirname(__FILE__)) + ::File::SEPARATOR
22
+ PATH = ::File.dirname(LIBPATH) + ::File::SEPARATOR
23
+ # :startdoc:
24
+
25
+ # Returns the version string for the library.
26
+ #
27
+ def self.version
28
+ VERSION
29
+ end
30
+
31
+ # Returns the library path for the module. If any arguments are given,
32
+ # they will be joined to the end of the libray path using
33
+ # <tt>File.join</tt>.
34
+ #
35
+ def self.libpath( *args )
36
+ args.empty? ? LIBPATH : ::File.join(LIBPATH, args.flatten)
37
+ end
38
+
39
+ # Returns the lpath for the module. If any arguments are given,
40
+ # they will be joined to the end of the path using
41
+ # <tt>File.join</tt>.
42
+ #
43
+ def self.path( *args )
44
+ args.empty? ? PATH : ::File.join(PATH, args.flatten)
45
+ end
46
+
47
+ # Utility method used to require all files ending in .rb that lie in the
48
+ # directory below this file that has the same name as the filename passed
49
+ # in. Optionally, a specific _directory_ name can be passed in such that
50
+ # the _filename_ does not have to be equivalent to the directory.
51
+ #
52
+ def self.require_all_libs_relative_to( fname, dir = nil )
53
+ dir ||= ::File.basename(fname, '.*')
54
+ search_me = ::File.expand_path(
55
+ ::File.join(::File.dirname(fname), dir, '**', '*.rb'))
56
+
57
+ Dir.glob(search_me).sort.each {|rb| require rb}
58
+ end
59
+
60
+ end # module Newsberry
61
+
62
+ Newsberry.require_all_libs_relative_to(__FILE__)
63
+
64
+ # EOF
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'net/http'
3
+ require 'uri'
4
+ require 'csv'
5
+
6
+ module Newsberry
7
+ class List
8
+
9
+ attr_accessor :list_name, :custom_fields, :data
10
+
11
+ def initialize(name)
12
+ @list_name = name
13
+ end
14
+
15
+ def sync!
16
+
17
+ req = Net::HTTP::Post.new('/api/subscriber.asmx/SynchronizeSubscribers')
18
+
19
+ req.basic_auth Newsberry.auth[:username], Newsberry.auth[:password] if Newsberry.auth
20
+
21
+ form_data = {
22
+ 'licenseKey' => Newsberry.api_key,
23
+ 'listName' => list_name,
24
+ 'emailsList' => build_data,
25
+ 'columnsList' => columns,
26
+ }
27
+
28
+ req.set_form_data(form_data)
29
+
30
+ res = Net::HTTP.new(Newsberry.host).start {|http| http.request(req) }
31
+ res.error! unless Net::HTTPSuccess === res
32
+ res
33
+ end
34
+
35
+
36
+ def columns
37
+ return 'Email' if custom_fields.nil?
38
+ build_csv do |writer|
39
+ writer << ['Email'] + custom_fields.map(&:last)
40
+ end
41
+ end
42
+
43
+ def build_data
44
+ build_csv do |writer|
45
+ @data.inject(writer) do | rows, record |
46
+ row = [record.email]
47
+ if custom_fields
48
+ custom_fields.map(&:first).each do |key|
49
+ row << record.send(key)
50
+ end
51
+ end
52
+
53
+ writer << row
54
+ writer
55
+ end
56
+ end
57
+ end
58
+
59
+ private
60
+
61
+ def build_csv
62
+ out = ""
63
+ CSV::Writer.generate out do |writer|
64
+ yield writer
65
+ end
66
+ out
67
+ end
68
+
69
+ end
70
+ end
@@ -0,0 +1,4 @@
1
+ :api_key: 00000000-0000-0000-0000-000000000000
2
+ :host: newsberry.com
3
+ :username: your-username
4
+ :password: your-password
@@ -0,0 +1,42 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+ require 'yaml'
3
+
4
+ class NewsberryTest < Test::Unit::TestCase
5
+
6
+ context "Newsberry" do
7
+ setup do
8
+ c = YAML::load_file("test/credentials.yml")
9
+ @api_key = c[:api_key]
10
+ Newsberry.configure do |config|
11
+ config.api_key = c[:api_key]
12
+ config.host = c[:host]
13
+ config.auth = {:username => c[:username], :password => c[:password]}
14
+ end
15
+ end
16
+
17
+ should "allow to be configured" do
18
+ assert_equal @api_key, Newsberry.api_key
19
+ end
20
+
21
+ context "List" do
22
+ setup do
23
+ @list = Newsberry::List.new('my-list')
24
+ @list.custom_fields = [ [:name, 'First Name'], [:nick, 'Nick'] ]
25
+ @list.data = [stub(:email => 'petyo@wildbit.com', :name => 'Petyo Ivanov', :nick => 'underlog')]
26
+ end
27
+
28
+ should "build the post data correctly" do
29
+ assert_equal "petyo@wildbit.com,Petyo Ivanov,underlog\n", @list.build_data
30
+ assert_equal "Email,First Name,Nick\n", @list.columns
31
+ end
32
+
33
+ should "post to newsberry" do
34
+ Net::HTTP.any_instance.expects(:request).returns(Net::HTTPOK.new(nil, '200', 'OK'))
35
+ @list.sync!
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+
42
+ end
@@ -0,0 +1,9 @@
1
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
2
+ $: << File.join(File.dirname(__FILE__))
3
+
4
+ require 'rubygems'
5
+ require 'test/unit'
6
+ require 'shoulda'
7
+ require 'mocha'
8
+ require 'newsberry'
9
+ require 'newsberry/list'
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wildbit-newsberry
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Petyo Ivanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-21 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bones
17
+ type: :development
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.4.2
24
+ version:
25
+ description: Simple package that allows you to manage your newsberry contacts.
26
+ email: petyo@wildbit.com
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - History.txt
33
+ - README.txt
34
+ files:
35
+ - .gitignore
36
+ - History.txt
37
+ - README.txt
38
+ - Rakefile
39
+ - lib/newsberry.rb
40
+ - lib/newsberry/list.rb
41
+ - test/credentials.yml.sample
42
+ - test/newsberry_test.rb
43
+ - test/test_helper.rb
44
+ has_rdoc: true
45
+ homepage: http://newsberry.com
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --main
49
+ - README.txt
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: newsberry
67
+ rubygems_version: 1.2.0
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Simple package that allows you to manage your newsberry contacts
71
+ test_files:
72
+ - test/test_helper.rb