Module: Transifex

Defined in:
lib/transifex/project.rb,
lib/transifex.rb,
lib/transifex/json.rb,
lib/transifex/errors.rb,
lib/transifex/formats.rb,
lib/transifex/version.rb,
lib/transifex/language.rb,
lib/transifex/projects.rb,
lib/transifex/resource.rb,
lib/transifex/languages.rb,
lib/transifex/resources.rb,
lib/transifex/crud_requests.rb,
lib/transifex/resource_components/stats.rb,
lib/transifex/resource_components/source.rb,
lib/transifex/project_components/language.rb,
lib/transifex/resource_components/content.rb,
lib/transifex/project_components/languages.rb,
lib/transifex/resource_components/translation.rb,
lib/transifex/project_components/language_components/reviewers.rb,
lib/transifex/resource_components/translation_components/string.rb,
lib/transifex/project_components/language_components/translators.rb,
lib/transifex/resource_components/translation_components/strings.rb,
lib/transifex/project_components/language_components/coordinators.rb,
lib/transifex/resource_components/translation_components/utilities.rb

Overview

Add a method add_resource to create a new resource for the project Add a method get_resources to fetch all the resources

Defined Under Namespace

Modules: CrudRequests, JSON, ProjectComponents, ResourceComponents Classes: Configuration, Error, Formats, Language, Languages, MissingParametersError, ParametersFormatError, Project, Projects, Resource, Resources, TransifexError

Constant Summary collapse

VERSION =
"0.0.1"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



44
45
46
# File 'lib/transifex.rb', line 44

def configuration
  @configuration
end

Class Method Details

.build_request_url(url = '') ⇒ Object



52
53
54
# File 'lib/transifex.rb', line 52

def self.build_request_url(url='')
  URI(self.configuration.root_url + url)    
end

.configure {|configuration| ... } ⇒ Object

Yields:



47
48
49
50
# File 'lib/transifex.rb', line 47

def self.configure
  self.configuration ||= Configuration.new
  yield configuration
end

.query_api(method, url, params = {}) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/transifex.rb', line 56

def self.query_api(method, url, params={})
  uri = build_request_url(url)

  res = Net::HTTP.start(uri.host, 80) do |http|
    req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, request_headers)
    req.basic_auth self.configuration., self.configuration.client_secret
    req.body = Transifex::JSON.dump(params)
    http.request req
  end

  begin
    data = Transifex::JSON.load(res.body.nil? ? '' : res.body)
  rescue
    data = res.body
  end

  unless (res.is_a? Net::HTTPOK) || (res.is_a? Net::HTTPCreated) || (res.is_a? Net::HTTPNoContent)
    error = TransifexError.new(uri, res.code, data)
    raise error
  end    

  data
end

.request_headersObject



80
81
82
83
84
85
86
# File 'lib/transifex.rb', line 80

def self.request_headers    
  request_headers = {      
    'Content-Type' => 'application/json',
    'Accept' => 'application/json',
    'User-Agent' => "Transifex-interface-ruby/#{Transifex::VERSION}"
  }    
end