statwing 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2b5c31fa4a0dbcff7bdd36ab85f569b50d367613
4
+ data.tar.gz: 39fbac854218d620ba482213c00a1685663c61b2
5
+ SHA512:
6
+ metadata.gz: d1f0324e52b9550520a0323f99294dbbe81f4f5d0d9a5bef4f90d6a6a1047b73b9dffc658162d7aeac82eb66771813b8589f0378d95028affef03dddecd761e8
7
+ data.tar.gz: afe65a6f242af64e99982094244344101e5c35e2b27976cc0efca1ea50eaa89dec4e3fed84c28382c25d5e435f60eb669f82623a51347eae73ae539cf94f6e23
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in statwing.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Matthew Dodds
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,71 @@
1
+ # Statwing
2
+
3
+ Ruby wrapper for the Statwing Api. This is accomplished using the [HER](https://github.com/remiprev/her) Object Relational Mapper.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'statwing'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install statwing
20
+
21
+ ## Configuration
22
+
23
+ ```ruby
24
+ Statwing.configure do |config|
25
+ config.api_key = 'your_api_key'
26
+ end
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ Creating a User and associating a new dataset:
32
+
33
+ ```ruby
34
+ @user = Statwing::User.create(partner_user_id: 'identifier')
35
+ => #<Statwing::User(users/usr_e9gAmn3WuEeDKjDwELRisB2lNYvAJMZa) partner_user_identity="identifier" id="usr_e9gAmn3WuEeDKjDwELRisB2lNYvAJMZa">
36
+
37
+ @dataset = Statwing::Dataset.create(name: "real-estate-transactions-sample.csv",fileurl: 'https://gist.githubusercontent.com/MatthewRDodds/5bf959ec16b67fd7c421/raw/52089a06e2fc9f8b74b85f49922f792610f3b6ae/real-estate-transactions-sample.csv', users: {action: 'add', data: [{ object: 'user_id', data: "usr_e9gAmn3WuEeDKjDwELRisB2lNYvAJMZa" }]})
38
+ => #<Statwing::Dataset:0x3fff3d1023c8>
39
+
40
+ @user.datasets
41
+ => [#<Statwing::Dataset:0x3fff3d5fe0d4>]
42
+ Statwing::Dataset.create(fileurl: 'https://gist.github.com/sandbox/6983768/raw/81e00eff263d6ac9fdedbe28de7d33dc8e850f2f/statwing.csv',name: 'statwing.csv',shared: 'restricted',action: 'add',users: [{object: 'user_id', data: 'usr_cNUWGust9V9xPFdXg6Ggv5rUnO7b3mUa'}])
43
+
44
+ @dataset.attributes
45
+ => {"name"=>"real-estate-transactions-sample.csv",
46
+ "filesize"=>113183,
47
+ "state"=>"processed",
48
+ "shared"=>"restricted",
49
+ "created_at"=>"2015-04-08T15:07:11Z",
50
+ "parse_settings"=>{"parser"=>"csv"},
51
+ "url_base"=>
52
+ "https://export.statwing.com/p0/datasets/dat_ufz8Ycgo0NiWSjICDYNCfzszXgqUeRrQ",
53
+ "users"=>nil}
54
+
55
+ @user.datasets.first.id
56
+ => "dat_ufz8Ycgo0NiWSjICDYNCfzszXgqUeRrQ"
57
+
58
+ Statwing::Dataset.find('dat_ufz8Ycgo0NiWSjICDYNCfzszXgqUeRrQ').users
59
+ => [{"id"=>"usr_e9gAmn3WuEeDKjDwELRisB2lNYvAJMZa",
60
+ "partner_user_id"=>"identifier",
61
+ "url"=>
62
+ "https://export.statwing.com/p0/datasets/dat_ufz8Ycgo0NiWSjICDYNCfzszXgqUeRrQ/users/usr_e9gAmn3WuEeDKjDwELRisB2lNYvAJMZa"}]
63
+ ```
64
+
65
+ ## Contributing
66
+
67
+ 1. Fork it ( https://github.com/[my-github-username]/statwing/fork )
68
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
69
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
70
+ 4. Push to the branch (`git push origin my-new-feature`)
71
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/lib/statwing.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'statwing/version'
2
+
3
+ require 'active_support'
4
+ require 'active_support/core_ext/string'
5
+
6
+ require 'json'
7
+ require 'her'
8
+
9
+ require 'statwing/middleware/authentication'
10
+ require 'statwing/middleware/parser'
11
+ require 'statwing/configuration'
12
+ require 'statwing/api'
13
+
14
+ require 'statwing/models/shared/model'
15
+ require 'statwing/models/shared/creatable'
16
+ require 'statwing/models/dataset'
17
+ require 'statwing/models/user'
@@ -0,0 +1,8 @@
1
+ ssl_options = { verify: true, verify_mode: OpenSSL::SSL::VERIFY_NONE }
2
+
3
+ Her::API.setup url: Statwing::API_URL, ssl: ssl_options do |c|
4
+ c.use Statwing::Authentication
5
+ c.use Faraday::Request::UrlEncoded
6
+ c.use Statwing::Parser
7
+ c.use Faraday::Adapter::NetHttp
8
+ end
@@ -0,0 +1,23 @@
1
+ module Statwing
2
+ API_URL = 'https://www.statwing.com/api/p0/'
3
+
4
+ class Configuration
5
+ attr_accessor :api_key
6
+
7
+ def initialize
8
+ @api_key = ''
9
+ end
10
+ end
11
+
12
+ class << self
13
+ attr_writer :configuration
14
+
15
+ def configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def configure
20
+ yield(configuration)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ module Statwing
2
+ class Authentication < Faraday::Middleware
3
+ def call(env)
4
+ key = Base64.encode64(Statwing.configuration.api_key).gsub!("\n", '')
5
+ env[:request_headers]["Authorization"] = "Basic #{key}:"
6
+
7
+ @app.call(env)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,16 @@
1
+ module Statwing
2
+ class Parser < Faraday::Response::Middleware
3
+ def on_complete(env)
4
+ json = JSON.parse(env[:body], :symbolize_names => true)
5
+ error = json.delete(:error) || {}
6
+
7
+ # Raise error when request returns an error
8
+ if error.present?
9
+ fail "#{error[:type].classify}: #{error[:message]}"
10
+ end
11
+
12
+ metadata = json.delete(:metadata) || []
13
+ env[:body] = { :data => json, :errors => error, :metadata => metadata }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,7 @@
1
+ module Statwing
2
+ class Dataset
3
+ include Model
4
+ include Creatable
5
+ end
6
+ end
7
+
@@ -0,0 +1,19 @@
1
+ module Statwing
2
+ module Creatable
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def element_name
7
+ @element_name ||= model_name.element.to_sym
8
+ end
9
+
10
+ def root
11
+ @root ||= root_element.to_s
12
+ end
13
+
14
+ def create(attrs)
15
+ new post_raw(root, Hash[element_name, attrs])[:parsed_data][:data]
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,12 @@
1
+ module Statwing
2
+ module Model
3
+ extend ActiveSupport::Concern
4
+
5
+ included do
6
+ include Her::Model
7
+
8
+ include_root_in_json true
9
+ parse_root_in_json true, format: :json_api
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ module Statwing
2
+ class User
3
+ include Model
4
+ include Creatable
5
+
6
+ has_many :datasets
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Statwing
2
+ VERSION = "0.0.1"
3
+ end
data/statwing.gemspec ADDED
@@ -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 'statwing/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'statwing'
8
+ spec.version = Statwing::VERSION
9
+ spec.authors = ['Matthew Dodds']
10
+ spec.email = ['matthewrusselldodds@gmail.com']
11
+ spec.summary = %q{Ruby wrapper for Statwing Api}
12
+ spec.description = 'Provides easy access to the statwing api for Ruby applications'
13
+ spec.homepage = 'http://github.com/MatthewRDodds/statwing'
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.require_paths = ['lib']
19
+
20
+ spec.add_runtime_dependency 'her', '~> 0.7'
21
+ spec.add_runtime_dependency 'activesupport', '~> 4.2'
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.7'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'pry', '~> 0.10'
26
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: statwing
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Dodds
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-04-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: her
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.7'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.7'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.10'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.10'
83
+ description: Provides easy access to the statwing api for Ruby applications
84
+ email:
85
+ - matthewrusselldodds@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".ruby-version"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/statwing.rb
97
+ - lib/statwing/api.rb
98
+ - lib/statwing/configuration.rb
99
+ - lib/statwing/middleware/authentication.rb
100
+ - lib/statwing/middleware/parser.rb
101
+ - lib/statwing/models/dataset.rb
102
+ - lib/statwing/models/shared/creatable.rb
103
+ - lib/statwing/models/shared/model.rb
104
+ - lib/statwing/models/user.rb
105
+ - lib/statwing/version.rb
106
+ - statwing.gemspec
107
+ homepage: http://github.com/MatthewRDodds/statwing
108
+ licenses:
109
+ - MIT
110
+ metadata: {}
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 2.4.5
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: Ruby wrapper for Statwing Api
131
+ test_files: []