contactually 0.0.1

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 49271ce9cdbe5ab97a80148d14406aa7ca00c2b8
4
+ data.tar.gz: 7396b1e527d6611147724e6c92de898ced9d650b
5
+ SHA512:
6
+ metadata.gz: 6c38457e05668eb5d0f190988919ddda5395e75102b01acb3884868492d7724fe0ef37b60038888054149e6890eafc2fbc852db2f85ce42332ccd472d242f527
7
+ data.tar.gz: c15ffc99cc297d42e025a7b6327a6efe1407e2f5c6dc20c21dfcc64e7dd8a564742efd0c6b9305b1f2c3ba4ee501bad3adee85224f81fb33cce3ed6f68150cf3
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "curb"
4
+
5
+ group :test do
6
+ gem 'minitest'
7
+ end
8
+ # Specify your gem's dependencies in contactually.gemspec
9
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Guille Carlos
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.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Contactually
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'contactually'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install contactually
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.test_files = FileList['test/*_test.rb']
7
+ t.verbose = true
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'contactually/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "contactually"
8
+ gem.version = Contactually::VERSION
9
+ gem.authors = ["Guille Carlos"]
10
+ gem.email = ["guille@bitpop.in"]
11
+ gem.description = %q{Gem for Contactually application}
12
+ gem.summary = %q{Gem for Contactually application}
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
@@ -0,0 +1,3 @@
1
+ module Contactually
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,46 @@
1
+ require "contactually/version"
2
+ require "json"
3
+
4
+ module Contactually
5
+ class API
6
+ def initialize(api_key)
7
+ @api_key = api_key
8
+ end
9
+
10
+ def call(method, args)
11
+ parsed_response = make_call(method, args)
12
+ parsed_response
13
+ end
14
+
15
+ def method_missing(method, *args)
16
+ call(method, args)
17
+ end
18
+
19
+ private
20
+ def param_fields(args)
21
+ params = {}
22
+ params = args.first.merge(params) if args.first
23
+ params
24
+ end
25
+
26
+ def make_call(method, args={})
27
+ http_method, contactually_method = get_methods(method)
28
+ uri = build_uri(contactually_method, args)
29
+ response = Curl.send(http_method.to_sym, uri, JSON.dump(param_fields(args))) do |curl|
30
+ curl.headers['Accept'] = 'application/json'
31
+ curl.headers['Content-Type'] = 'application/json'
32
+ end
33
+ JSON.load("[#{response.body_str}]").first
34
+ end
35
+
36
+ def build_uri(contactually_method, args={})
37
+ #return "https://www.contactually.com/api/v1/#{contactually_method}/#{args[:id]}.json" if args[:id]
38
+ "https://www.contactually.com/api/v1/#{contactually_method}.json?api_key=#{@api_key}"
39
+ end
40
+
41
+ def get_methods(method)
42
+ methods = method.to_s.split("_", 2)
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ require "test_helper"
2
+ require "contactually"
3
+ require "curb"
4
+ require "minitest/mock"
5
+
6
+ describe "Contactually API method calls samples" do
7
+
8
+ before do
9
+ @api_key = "i8d6k1y1hjbrbh6qochplf3vkxtapqul"
10
+ @contactually = Contactually::API.new(@api_key)
11
+
12
+ #Fake Response
13
+ FakeResponse = Struct.new(:body_str)
14
+ @response = FakeResponse.new("{}")
15
+ @mock = MiniTest::Mock.new
16
+ @mock.expect :body_str, @response.body_str
17
+ end
18
+
19
+ it "can call a contact" do
20
+
21
+ #Curl.stub(:post, @mock) do
22
+ @contactually.post_contact
23
+ #end
24
+
25
+ #assert @mock.verify
26
+ end
27
+
28
+ end
29
+
30
+ describe "Method Builder" do
31
+ before do
32
+ @api_key = "i8d6k1y1hjbrbh6qochplf3vkxtapqul"
33
+ @contactually = Contactually::API.new(@api_key)
34
+ end
35
+
36
+ it "should return a http_method and contactually method" do
37
+ assert @contactually.send(:get_methods, :post_contact) == ["post", "contact"]
38
+ end
39
+
40
+ it "should build a uri with no id" do
41
+ test_method = "contact"
42
+ test_uri = "https://www.contactually.com/api/v1/#{test_method}.json"
43
+ assert @contactually.send(:build_uri, "contact") == test_uri
44
+ end
45
+
46
+ it "should build a uri with id" do
47
+ test_method = "contact"
48
+ args_hash = { id: 1 }
49
+ test_uri = "https://www.contactually.com/api/v1/#{test_method}/#{args_hash[:id]}.json"
50
+ assert @contactually.send(:build_uri, "contact", args_hash) == test_uri
51
+ end
52
+
53
+ end
@@ -0,0 +1 @@
1
+ require 'minitest/autorun'
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: contactually
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Guille Carlos
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-03 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Gem for Contactually application
14
+ email:
15
+ - guille@bitpop.in
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - Gemfile
22
+ - LICENSE.txt
23
+ - README.md
24
+ - Rakefile
25
+ - contactually.gemspec
26
+ - lib/contactually.rb
27
+ - lib/contactually/version.rb
28
+ - test/contactually_test.rb
29
+ - test/test_helper.rb
30
+ homepage: ''
31
+ licenses: []
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.0.3
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Gem for Contactually application
53
+ test_files:
54
+ - test/contactually_test.rb
55
+ - test/test_helper.rb